summaryrefslogtreecommitdiffstats
path: root/vendor/signature/tests/derive.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/signature/tests/derive.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/signature/tests/derive.rs')
-rw-r--r--vendor/signature/tests/derive.rs40
1 files changed, 24 insertions, 16 deletions
diff --git a/vendor/signature/tests/derive.rs b/vendor/signature/tests/derive.rs
index 5048dc682..70e2dc0fc 100644
--- a/vendor/signature/tests/derive.rs
+++ b/vendor/signature/tests/derive.rs
@@ -1,13 +1,13 @@
//! Tests for code generated by `signature_derive`
-#![cfg(all(feature = "derive-preview", feature = "hazmat-preview"))]
+#![cfg(feature = "derive")]
use digest::{generic_array::GenericArray, Digest, OutputSizeUser};
use hex_literal::hex;
use sha2::Sha256;
use signature::{
hazmat::{PrehashSigner, PrehashVerifier},
- DigestSigner, DigestVerifier, Error, PrehashSignature, Signature, Signer, Verifier,
+ DigestSigner, DigestVerifier, Error, PrehashSignature, SignatureEncoding, Signer, Verifier,
};
/// Test vector to compute SHA-256 digest of
@@ -17,35 +17,43 @@ const INPUT_STRING: &[u8] = b"abc";
const INPUT_STRING_DIGEST: [u8; 32] =
hex!("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad");
+type Repr = GenericArray<u8, <Sha256 as OutputSizeUser>::OutputSize>;
+
/// Dummy signature which just contains a digest output
-#[derive(Debug)]
-struct DummySignature(GenericArray<u8, <Sha256 as OutputSizeUser>::OutputSize>);
+#[derive(Clone, Debug)]
+struct DummySignature(Repr);
+
+impl PrehashSignature for DummySignature {
+ type Digest = Sha256;
+}
+
+impl SignatureEncoding for DummySignature {
+ type Repr = Repr;
+}
+
+impl TryFrom<&[u8]> for DummySignature {
+ type Error = Error;
-impl Signature for DummySignature {
- fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
+ fn try_from(bytes: &[u8]) -> Result<Self, Error> {
Ok(DummySignature(GenericArray::clone_from_slice(
bytes.as_ref(),
)))
}
}
-impl AsRef<[u8]> for DummySignature {
- fn as_ref(&self) -> &[u8] {
- self.0.as_ref()
+impl From<DummySignature> for Repr {
+ fn from(sig: DummySignature) -> Repr {
+ sig.0
}
}
-impl PrehashSignature for DummySignature {
- type Digest = Sha256;
-}
-
/// Dummy signer which just returns the message digest as a `DummySignature`
#[derive(Signer, DigestSigner, Default)]
struct DummySigner {}
impl PrehashSigner<DummySignature> for DummySigner {
fn sign_prehash(&self, prehash: &[u8]) -> signature::Result<DummySignature> {
- DummySignature::from_bytes(prehash)
+ DummySignature::try_from(prehash)
}
}
@@ -58,7 +66,7 @@ struct DummyVerifier {}
impl PrehashVerifier<DummySignature> for DummyVerifier {
fn verify_prehash(&self, prehash: &[u8], signature: &DummySignature) -> signature::Result<()> {
- assert_eq!(signature.as_ref(), prehash);
+ assert_eq!(signature.to_bytes().as_slice(), prehash);
Ok(())
}
}
@@ -66,7 +74,7 @@ impl PrehashVerifier<DummySignature> for DummyVerifier {
#[test]
fn derived_signer_impl() {
let sig: DummySignature = DummySigner::default().sign(INPUT_STRING);
- assert_eq!(sig.as_ref(), INPUT_STRING_DIGEST.as_ref())
+ assert_eq!(sig.to_bytes().as_slice(), INPUT_STRING_DIGEST.as_ref())
}
#[test]