Skip to content

Commit 77c8d8f

Browse files
Use a sequence of bytes (representing AriesMessage) as input for EncryptionEnvelope::create (#1007)
* Use a sequence of bytes (representing AriesMessage) as input for EncryptionEnvelope::create Signed-off-by: Naian <126972030+nain-F49FF806@users.noreply.github.com>
1 parent 34c35de commit 77c8d8f

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

aries_vcx/src/protocols/connection/generic/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ impl GenericConnection {
180180
AriesVcxErrorKind::NotReady,
181181
"No DidDoc present",
182182
))?;
183-
EncryptionEnvelope::create(wallet, message, Some(sender_verkey), did_doc).await
183+
EncryptionEnvelope::create(
184+
wallet,
185+
json!(message).to_string().as_bytes(),
186+
Some(sender_verkey),
187+
did_doc,
188+
)
189+
.await
184190
}
185191

186192
pub async fn send_message<T>(

aries_vcx/src/protocols/connection/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ where
100100
message: &AriesMessage,
101101
) -> VcxResult<EncryptionEnvelope> {
102102
let sender_verkey = &self.pairwise_info().pw_vk;
103-
EncryptionEnvelope::create(wallet, message, Some(sender_verkey), self.their_did_doc()).await
103+
EncryptionEnvelope::create(
104+
wallet,
105+
json!(message).to_string().as_bytes(),
106+
Some(sender_verkey),
107+
self.their_did_doc(),
108+
)
109+
.await
104110
}
105111

106112
pub fn remote_did(&self) -> &str {

aries_vcx/src/utils/encryption_envelope.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ use crate::{errors::error::prelude::*, global::settings, utils::constants};
1414
pub struct EncryptionEnvelope(pub Vec<u8>);
1515

1616
impl EncryptionEnvelope {
17+
/// Create an Encryption Envelope from a plaintext AriesMessage encoded as sequence of bytes.
18+
/// If did_doc includes routing_keys, then also wrap in appropriate layers of forward message.
1719
pub async fn create(
1820
wallet: &impl BaseWallet,
19-
message: &AriesMessage,
21+
message: &[u8],
2022
pw_verkey: Option<&str>,
2123
did_doc: &AriesDidDoc,
2224
) -> VcxResult<EncryptionEnvelope> {
@@ -41,12 +43,10 @@ impl EncryptionEnvelope {
4143

4244
async fn encrypt_for_pairwise(
4345
wallet: &impl BaseWallet,
44-
message: &AriesMessage,
46+
message: &[u8],
4547
pw_verkey: Option<&str>,
4648
did_doc: &AriesDidDoc,
4749
) -> VcxResult<Vec<u8>> {
48-
let message = json!(message).to_string();
49-
5050
let receiver_keys = json!(did_doc.recipient_keys()?).to_string();
5151

5252
debug!(
@@ -55,7 +55,7 @@ impl EncryptionEnvelope {
5555
);
5656

5757
wallet
58-
.pack_message(pw_verkey, &receiver_keys, message.as_bytes())
58+
.pack_message(pw_verkey, &receiver_keys, message)
5959
.await
6060
.map_err(|err| err.into())
6161
}

aries_vcx/src/utils/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ pub async fn send_message(
5656
message,
5757
&did_doc
5858
);
59-
let EncryptionEnvelope(envelope) =
60-
EncryptionEnvelope::create(wallet, &message, Some(&sender_verkey), &did_doc).await?;
59+
60+
let EncryptionEnvelope(envelope) = EncryptionEnvelope::create(
61+
wallet,
62+
json!(message).to_string().as_bytes(),
63+
Some(&sender_verkey),
64+
&did_doc,
65+
)
66+
.await?;
6167

6268
// TODO: Extract from agency client
6369
agency_client::httpclient::post_message(
@@ -81,7 +87,8 @@ pub async fn send_message_anonymously(
8187
&did_doc
8288
);
8389
let EncryptionEnvelope(envelope) =
84-
EncryptionEnvelope::create(wallet, message, None, did_doc).await?;
90+
EncryptionEnvelope::create(wallet, json!(message).to_string().as_bytes(), None, did_doc)
91+
.await?;
8592

8693
agency_client::httpclient::post_message(
8794
envelope,

0 commit comments

Comments
 (0)