Commit
+26 -25 +/-5 browse
1 | diff --git a/Cargo.toml b/Cargo.toml |
2 | index 196a6da..a6e2250 100644 |
3 | --- a/Cargo.toml |
4 | +++ b/Cargo.toml |
5 | @@ -22,7 +22,7 @@ test = [] |
6 | |
7 | [dependencies] |
8 | ahash = "0.8.0" |
9 | - ed25519-dalek = { version = "1.0", optional = true } |
10 | + ed25519-dalek = { version = "2.0", optional = true } |
11 | flate2 = "1.0.25" |
12 | lru-cache = "0.1.2" |
13 | mail-parser = { version = "0.9", git = "https://github.com/stalwartlabs/mail-parser", features = ["ludicrous_mode", "full_encoding"] } |
14 | diff --git a/examples/dkim_sign.rs b/examples/dkim_sign.rs |
15 | index bb96b6e..9f85e05 100644 |
16 | --- a/examples/dkim_sign.rs |
17 | +++ b/examples/dkim_sign.rs |
18 | @@ -64,11 +64,8 @@ fn main() { |
19 | |
20 | // Sign an e-mail message using ED25519-SHA256 |
21 | #[cfg(feature = "rust-crypto")] |
22 | - let pk_ed = Ed25519Key::from_bytes( |
23 | - &base64_decode(ED25519_PUBLIC_KEY.as_bytes()).unwrap(), |
24 | - &base64_decode(ED25519_PRIVATE_KEY.as_bytes()).unwrap(), |
25 | - ) |
26 | - .unwrap(); |
27 | + let pk_ed = |
28 | + Ed25519Key::from_bytes(&base64_decode(ED25519_PRIVATE_KEY.as_bytes()).unwrap()).unwrap(); |
29 | #[cfg(all(feature = "ring", not(feature = "rust-crypto")))] |
30 | let pk_ed = Ed25519Key::from_seed_and_public_key( |
31 | &base64_decode(ED25519_PRIVATE_KEY.as_bytes()).unwrap(), |
32 | diff --git a/src/arc/seal.rs b/src/arc/seal.rs |
33 | index 464bc9c..a854e3c 100644 |
34 | --- a/src/arc/seal.rs |
35 | +++ b/src/arc/seal.rs |
36 | @@ -293,7 +293,7 @@ mod test { |
37 | "scamorza.org", |
38 | "ed", |
39 | #[cfg(feature = "rust-crypto")] |
40 | - Ed25519Key::from_bytes(&pk_ed_public, &pk_ed_private).unwrap(), |
41 | + Ed25519Key::from_bytes(&pk_ed_private).unwrap(), |
42 | #[cfg(all(feature = "ring", not(feature = "rust-crypto")))] |
43 | Ed25519Key::from_seed_and_public_key(&pk_ed_private, &pk_ed_public).unwrap(), |
44 | ) |
45 | diff --git a/src/common/crypto/rust_crypto.rs b/src/common/crypto/rust_crypto.rs |
46 | index c5b16fc..2ec8966 100644 |
47 | --- a/src/common/crypto/rust_crypto.rs |
48 | +++ b/src/common/crypto/rust_crypto.rs |
49 | @@ -1,3 +1,4 @@ |
50 | + use std::array::TryFromSliceError; |
51 | use std::marker::PhantomData; |
52 | |
53 | use ed25519_dalek::Signer; |
54 | @@ -79,19 +80,18 @@ impl SigningKey for RsaKey<Sha256> { |
55 | } |
56 | |
57 | pub struct Ed25519Key { |
58 | - inner: ed25519_dalek::Keypair, |
59 | + inner: ed25519_dalek::SigningKey, |
60 | } |
61 | |
62 | impl Ed25519Key { |
63 | /// Creates an Ed25519 private key |
64 | - pub fn from_bytes(public_key_bytes: &[u8], private_key_bytes: &[u8]) -> crate::Result<Self> { |
65 | + pub fn from_bytes(private_key_bytes: &[u8]) -> crate::Result<Self> { |
66 | Ok(Self { |
67 | - inner: ed25519_dalek::Keypair { |
68 | - public: ed25519_dalek::PublicKey::from_bytes(public_key_bytes) |
69 | - .map_err(|err| Error::CryptoError(err.to_string()))?, |
70 | - secret: ed25519_dalek::SecretKey::from_bytes(private_key_bytes) |
71 | - .map_err(|err| Error::CryptoError(err.to_string()))?, |
72 | - }, |
73 | + inner: ed25519_dalek::SigningKey::from_bytes( |
74 | + private_key_bytes |
75 | + .try_into() |
76 | + .map_err(|err: TryFromSliceError| Error::CryptoError(err.to_string()))?, |
77 | + ), |
78 | }) |
79 | } |
80 | } |
81 | @@ -166,7 +166,7 @@ impl VerifyingKey for RsaPublicKey { |
82 | } |
83 | |
84 | pub(crate) struct Ed25519PublicKey { |
85 | - inner: ed25519_dalek::PublicKey, |
86 | + inner: ed25519_dalek::VerifyingKey, |
87 | } |
88 | |
89 | impl Ed25519PublicKey { |
90 | @@ -174,8 +174,12 @@ impl Ed25519PublicKey { |
91 | bytes: &[u8], |
92 | ) -> Result<Box<dyn VerifyingKey + Send + Sync>> { |
93 | Ok(Box::new(Ed25519PublicKey { |
94 | - inner: ed25519_dalek::PublicKey::from_bytes(bytes) |
95 | - .map_err(|err| Error::CryptoError(err.to_string()))?, |
96 | + inner: ed25519_dalek::VerifyingKey::from_bytes( |
97 | + bytes |
98 | + .try_into() |
99 | + .map_err(|err: TryFromSliceError| Error::CryptoError(err.to_string()))?, |
100 | + ) |
101 | + .map_err(|err| Error::CryptoError(err.to_string()))?, |
102 | })) |
103 | } |
104 | } |
105 | @@ -199,8 +203,11 @@ impl VerifyingKey for Ed25519PublicKey { |
106 | self.inner |
107 | .verify_strict( |
108 | hash.as_ref(), |
109 | - &ed25519_dalek::Signature::from_bytes(signature) |
110 | - .map_err(|err| Error::CryptoError(err.to_string()))?, |
111 | + &ed25519_dalek::Signature::from_bytes( |
112 | + signature |
113 | + .try_into() |
114 | + .map_err(|err: TryFromSliceError| Error::CryptoError(err.to_string()))?, |
115 | + ), |
116 | ) |
117 | .map_err(|_| Error::FailedVerification) |
118 | } |
119 | diff --git a/src/dkim/sign.rs b/src/dkim/sign.rs |
120 | index a39aa84..c77fd92 100644 |
121 | --- a/src/dkim/sign.rs |
122 | +++ b/src/dkim/sign.rs |
123 | @@ -215,11 +215,8 @@ mod test { |
124 | |
125 | // Create private keys |
126 | #[cfg(feature = "rust-crypto")] |
127 | - let pk_ed = Ed25519Key::from_bytes( |
128 | - &base64_decode(ED25519_PUBLIC_KEY.rsplit_once("p=").unwrap().1.as_bytes()).unwrap(), |
129 | - &base64_decode(ED25519_PRIVATE_KEY.as_bytes()).unwrap(), |
130 | - ) |
131 | - .unwrap(); |
132 | + let pk_ed = Ed25519Key::from_bytes(&base64_decode(ED25519_PRIVATE_KEY.as_bytes()).unwrap()) |
133 | + .unwrap(); |
134 | #[cfg(all(feature = "ring", not(feature = "rust-crypto")))] |
135 | let pk_ed = Ed25519Key::from_seed_and_public_key( |
136 | &base64_decode(ED25519_PRIVATE_KEY.as_bytes()).unwrap(), |