Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/bin/rbw-agent/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,38 @@ pub async fn decrypt(
Ok(())
}

pub async fn decrypt_batch(
sock: &mut crate::sock::Sock,
state: std::sync::Arc<tokio::sync::Mutex<crate::state::State>>,
environment: &rbw::protocol::Environment,
entries: &[rbw::protocol::DecryptRequest],
) -> anyhow::Result<()> {
let mut results = Vec::with_capacity(entries.len());
for entry in entries {
let result = decrypt_cipher(
state.clone(),
environment,
&entry.cipherstring,
entry.entry_key.as_deref(),
entry.org_id.as_deref(),
)
.await;
results.push(match result {
Ok(plaintext) => {
rbw::protocol::DecryptResult::Success { plaintext }
}
Err(e) => rbw::protocol::DecryptResult::Failure {
error: format!("{e:#}"),
},
});
}

sock.send(&rbw::protocol::Response::DecryptBatch { results })
.await?;

Ok(())
}

pub async fn encrypt(
sock: &mut crate::sock::Sock,
state: std::sync::Arc<tokio::sync::Mutex<crate::state::State>>,
Expand Down
10 changes: 10 additions & 0 deletions src/bin/rbw-agent/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ async fn handle_request(
.await?;
true
}
rbw::protocol::Action::DecryptBatch { entries } => {
crate::actions::decrypt_batch(
sock,
state.clone(),
&environment,
entries,
)
.await?;
true
}
rbw::protocol::Action::Encrypt { plaintext, org_id } => {
crate::actions::encrypt(
sock,
Expand Down
19 changes: 19 additions & 0 deletions src/bin/rbw/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ pub fn decrypt(
}
}

pub fn decrypt_batch(
requests: Vec<rbw::protocol::DecryptRequest>,
) -> anyhow::Result<Vec<rbw::protocol::DecryptResult>> {
let mut sock = connect()?;
sock.send(&rbw::protocol::Request::new(
get_environment(),
rbw::protocol::Action::DecryptBatch { entries: requests },
))?;

let res = sock.recv()?;
match res {
rbw::protocol::Response::DecryptBatch { results } => Ok(results),
rbw::protocol::Response::Error { error } => {
Err(anyhow::anyhow!("failed to decrypt: {error}"))
}
_ => Err(anyhow::anyhow!("unexpected message: {res:?}")),
}
}

pub fn encrypt(
plaintext: &str,
org_id: Option<&str>,
Expand Down
Loading
Loading