Skip to content

Commit

Permalink
renaming method
Browse files Browse the repository at this point in the history
  • Loading branch information
heliannuuthus committed Aug 27, 2024
1 parent da3ec59 commit 9a183ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sm2/src/pke/decrypting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl DecryptingKey {
}

/// Decrypts a ciphertext in-place from ASN.1 format using the default digest algorithm (`Sm3`).
pub fn decrypt_asna1(&self, ciphertext: &[u8]) -> Result<Vec<u8>> {
pub fn decrypt_der(&self, ciphertext: &[u8]) -> Result<Vec<u8>> {
self.decrypt_asna1_digest::<Sm3>(ciphertext)
}

Expand Down
6 changes: 3 additions & 3 deletions sm2/src/pke/encrypting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl EncryptingKey {
///
/// This method calculates the digest using the `Sm3` hash function and performs encryption,
/// then encodes the result in ASN.1 format.
pub fn encrypt_asna1(&self, msg: &[u8]) -> Result<Vec<u8>> {
self.encrypt_asna1_digest::<Sm3>(msg)
pub fn encrypt_der(&self, msg: &[u8]) -> Result<Vec<u8>> {
self.encrypt_der_digest::<Sm3>(msg)
}

/// Encrypts a message using a specified digest algorithm.
Expand All @@ -98,7 +98,7 @@ impl EncryptingKey {
}

/// Encrypts a message using a specified digest algorithm and returns the result in ASN.1 format.
pub fn encrypt_asna1_digest<D>(&self, msg: &[u8]) -> Result<Vec<u8>>
pub fn encrypt_der_digest<D>(&self, msg: &[u8]) -> Result<Vec<u8>>
where
D: 'static + Digest + DynDigest + Send + Sync,
{
Expand Down
6 changes: 3 additions & 3 deletions sm2/tests/sm2pke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn decrypt_asna1_verify() {
NonZeroScalar::<Sm2>::try_from(PRIVATE_KEY.as_ref() as &[u8]).unwrap(),
sm2::pke::Mode::C1C2C3,
);
assert_eq!(dk.decrypt_asna1(&ASN1_CIPHER).unwrap(), MSG);
assert_eq!(dk.decrypt_der(&ASN1_CIPHER).unwrap(), MSG);
}

prop_compose! {
Expand Down Expand Up @@ -65,8 +65,8 @@ proptest! {
#[test]
fn encrypt_and_decrpyt_asna1(dk in decrypting_key()) {
let ek = dk.encrypting_key();
let cipher_bytes = ek.encrypt_asna1(MSG).unwrap();
prop_assert!(dk.decrypt_asna1(&cipher_bytes).is_ok());
let cipher_bytes = ek.encrypt_der(MSG).unwrap();
prop_assert!(dk.decrypt_der(&cipher_bytes).is_ok());
}

#[test]
Expand Down

0 comments on commit 9a183ab

Please sign in to comment.