Skip to content

Commit

Permalink
feat(rust): change import_private_identity to accept binary instead…
Browse files Browse the repository at this point in the history
… of hex
  • Loading branch information
SanjoDeundiak committed Aug 18, 2023
1 parent 0d0513c commit 6d19dbb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ async fn main(ctx: Context) -> Result<()> {
// which is an identifier known to the credential issuer, with some preset attributes
// We're hard coding this specific identity because its public identifier is known
// to the credential issuer as a member of the production cluster.
let change_history = "81a201583ba20101025835a4028201815820530d1c2e9822433b679a66a60b9c2ed47c370cd0ce51cbe1a7ad847b5835a96303f4041a64dd4060051a77a94360028201815840042fff8f6c80603fb1cec4a3cf1ff169ee36889d3ed76184fe1dfbd4b692b02892df9525c61c2f1286b829586d13d5abf7d18973141f734d71c1840520d40a0e";
let change_history = hex::decode("81a201583ba20101025835a4028201815820530d1c2e9822433b679a66a60b9c2ed47c370cd0ce51cbe1a7ad847b5835a96303f4041a64dd4060051a77a94360028201815840042fff8f6c80603fb1cec4a3cf1ff169ee36889d3ed76184fe1dfbd4b692b02892df9525c61c2f1286b829586d13d5abf7d18973141f734d71c1840520d40a0e").unwrap();
let secret = signing_vault
.import_key(
Secret::new(hex::decode("31FF4E1CD55F17735A633FBAB4B838CF88D1252D164735CB3185A6E315438C2C").unwrap()),
SecretAttributes::Ed25519,
)
.await?;
let client = node.import_private_identity(change_history, &secret).await?;
let client = node.import_private_identity(&change_history, &secret).await?;
node.identities()
.purpose_keys()
.create_purpose_key(client.identifier(), Purpose::SecureChannel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ async fn main(ctx: Context) -> Result<()> {
vault.signing_vault = signing_vault.clone();
let node = Node::builder().with_vault(vault).build(ctx).await?;

let issuer_identity = "81a201583ba20101025835a4028201815820afbca9cf5d440147450f9f0d0a038a337b3fe5c17086163f2c54509558b62ef403f4041a64dd404a051a77a9434a0282018158407754214545cda6e7ff49136f67c9c7973ec309ca4087360a9f844aac961f8afe3f579a72c0c9530f3ff210f02b7c5f56e96ce12ee256b01d7628519800723805";
let issuer_identity = hex::decode("81a201583ba20101025835a4028201815820afbca9cf5d440147450f9f0d0a038a337b3fe5c17086163f2c54509558b62ef403f4041a64dd404a051a77a9434a0282018158407754214545cda6e7ff49136f67c9c7973ec309ca4087360a9f844aac961f8afe3f579a72c0c9530f3ff210f02b7c5f56e96ce12ee256b01d7628519800723805").unwrap();
let secret = signing_vault
.import_key(
Secret::new(hex::decode("0127359911708ef4de9adaaf27c357501473c4a10a5326a69c1f7f874a0cd82e").unwrap()),
SecretAttributes::Ed25519,
)
.await?;

let issuer = node.import_private_identity(issuer_identity, &secret).await?;
let issuer = node.import_private_identity(&issuer_identity, &secret).await?;
node.identities()
.purpose_keys()
.create_purpose_key(issuer.identifier(), Purpose::SecureChannel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ async fn main(ctx: Context) -> Result<()> {
//
// We're hard coding this specific identity because its public identifier is known
// to the credential issuer as a member of the production cluster.
let change_history = "81a201583ba20101025835a40282018158201d387ce453816d91159740a55e9a62ad3b58be9ecf7ef08760c42c0d885b6c2e03f4041a64dd4074051a77a9437402820181584053de69d82c9c4b12476c889b437be1d9d33bd0041655c4836a3a57ac5a67703e7f500af5bacaed291cfd6783d255fe0f0606638577d087a5612bfb4671f2b70a";
let change_history = hex::decode("81a201583ba20101025835a40282018158201d387ce453816d91159740a55e9a62ad3b58be9ecf7ef08760c42c0d885b6c2e03f4041a64dd4074051a77a9437402820181584053de69d82c9c4b12476c889b437be1d9d33bd0041655c4836a3a57ac5a67703e7f500af5bacaed291cfd6783d255fe0f0606638577d087a5612bfb4671f2b70a").unwrap();
let secret = signing_vault
.import_key(
Secret::new(hex::decode("5FB3663DF8405379981462BABED7507E3D53A8D061188105E3ADBD70E0A74B8A").unwrap()),
SecretAttributes::Ed25519,
)
.await?;
let server = node.import_private_identity(change_history, &secret).await?;
let server = node.import_private_identity(&change_history, &secret).await?;
node.identities()
.purpose_keys()
.create_purpose_key(server.identifier(), Purpose::SecureChannel)
Expand Down
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ impl Node {
/// Note: the data is not persisted!
pub async fn import_private_identity(
&self,
identity_history: &str,
identity_change_history: &[u8],
key_id: &KeyId,
) -> Result<Identity> {
self.identities_creation()
.import_private_identity(identity_history, key_id)
.import_private_identity(identity_change_history, key_id)
.await
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ockam_core::compat::sync::Arc;
use ockam_core::compat::vec::Vec;
use ockam_core::Result;
use ockam_vault::{KeyId, SigningVault, VerifyingVault};

Expand Down Expand Up @@ -69,12 +68,10 @@ impl IdentitiesCreation {
/// Note: the data is not persisted!
pub async fn import_private_identity(
&self,
identity_history: &str,
identity_change_history: &[u8],
key_id: &KeyId,
) -> Result<Identity> {
let identity_history_data: Vec<u8> =
hex::decode(identity_history).map_err(|_| IdentityError::InvalidHex)?;
let identity = self.import(None, identity_history_data.as_slice()).await?;
let identity = self.import(None, identity_change_history).await?;
if identity.get_public_key()? != self.signing_vault.get_public_key(key_id).await? {
return Err(IdentityError::WrongSecretKey.into());
}
Expand Down

0 comments on commit 6d19dbb

Please sign in to comment.