Skip to content

Commit

Permalink
Use MessageType to bundle CryptoType and SignatureType together
Browse files Browse the repository at this point in the history
Signed-off-by: Michiel <[email protected]>
  • Loading branch information
michielp1807 committed Sep 4, 2024
1 parent 8e3cfd4 commit a5fe5c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
10 changes: 2 additions & 8 deletions tsp/src/crypto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::definitions::MessageType;
use crate::definitions::{
Digest, NonConfidentialData, Payload, PrivateKeyData, PrivateSigningKeyData, PrivateVid,
PublicKeyData, PublicVerificationKeyData, TSPMessage, VerifiedVid,
Expand Down Expand Up @@ -132,14 +133,7 @@ pub fn sign(
pub fn verify<'a>(
sender: &dyn VerifiedVid,
tsp_message: &'a mut [u8],
) -> Result<
(
&'a [u8],
crate::cesr::CryptoType,
crate::cesr::SignatureType,
),
CryptoError,
> {
) -> Result<(&'a [u8], MessageType), CryptoError> {
nonconfidential::verify(sender, tsp_message)
}

Expand Down
19 changes: 9 additions & 10 deletions tsp/src/crypto/nonconfidential.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
cesr::{CryptoType, DecodedEnvelope, Envelope, SignatureType},
definitions::{PrivateVid, TSPMessage, VerifiedVid},
definitions::{MessageType, PrivateVid, TSPMessage, VerifiedVid},
};
use ed25519_dalek::ed25519::signature::Signer;

Expand Down Expand Up @@ -37,14 +37,7 @@ pub fn sign(
pub fn verify<'a>(
sender: &dyn VerifiedVid,
tsp_message: &'a mut [u8],
) -> Result<
(
&'a [u8],
crate::cesr::CryptoType,
crate::cesr::SignatureType,
),
CryptoError,
> {
) -> Result<(&'a [u8], MessageType), CryptoError> {
let view = crate::cesr::decode_envelope(tsp_message)?;

// verify outer signature
Expand Down Expand Up @@ -72,5 +65,11 @@ pub fn verify<'a>(
return Err(CryptoError::MissingCiphertext);
};

Ok((nonconfidential_data, crypto_type, signature_type))
Ok((
nonconfidential_data,
MessageType {
crypto_type,
signature_type,
},
))
}
8 changes: 2 additions & 6 deletions tsp/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,17 +778,13 @@ impl Store {
return Err(Error::UnverifiedVid(sender.to_string()));
};

let (message, crypto_type, signature_type) =
crate::crypto::verify(&*sender_vid, message)?;
let (message, message_type) = crate::crypto::verify(&*sender_vid, message)?;

Ok(ReceivedTspMessage::GenericMessage {
sender,
nonconfidential_data: None,
message,
message_type: MessageType {
crypto_type,
signature_type,
},
message_type,
})
}
}
Expand Down

0 comments on commit a5fe5c7

Please sign in to comment.