1
//! Re-exporting Ed25519 implementations, and related utilities.
2
//!
3
//! Here we re-export types from [`ed25519_dalek`] that implement the
4
//! Ed25519 signature algorithm.  (TODO: Eventually, this module
5
//! should probably be replaced with a wrapper that uses the ed25519
6
//! trait and the Signature trait.)
7
//!
8
//! We additionally provide an `Ed25519Identity` type to represent the
9
//! unvalidated Ed25519 "identity keys" that we use throughout the Tor
10
//! protocol to uniquely identify a relay.
11

            
12
use base64ct::{Base64Unpadded, Encoding as _};
13
use curve25519_dalek::Scalar;
14
use derive_deftly::Deftly;
15
use safelog::util::write_start_redacted;
16
use std::fmt::{self, Debug, Display, Formatter};
17
use subtle::{Choice, ConstantTimeEq};
18

            
19
#[cfg(feature = "memquota-memcost")]
20
use tor_memquota_cost::derive_deftly_template_HasMemoryCost;
21

            
22
use ed25519_dalek::hazmat::ExpandedSecretKey;
23
use ed25519_dalek::{Signer as _, Verifier as _};
24

            
25
use crate::util::ct::{
26
    CtByteArray, derive_deftly_template_ConstantTimeEq, derive_deftly_template_PartialEqFromCtEq,
27
};
28

            
29
/// An Ed25519 signature.
30
///
31
/// See [`ed25519_dalek::Signature`] for more information.
32
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
33
pub struct Signature(pub(crate) ed25519_dalek::Signature);
34

            
35
/// An Ed25519 keypair.
36
///
37
/// (We do not provide a separate "private key only" type.)
38
///
39
/// See [`ed25519_dalek::SigningKey`] for more information.
40
#[derive(Debug, Deftly)]
41
#[derive_deftly(ConstantTimeEq)]
42
pub struct Keypair(pub(crate) ed25519_dalek::SigningKey);
43

            
44
/// An Ed25519 public key.
45
///
46
/// See [`ed25519_dalek::VerifyingKey`] for more information.
47
#[derive(Clone, Copy, Debug, Eq, Deftly)]
48
#[derive_deftly(PartialEqFromCtEq)]
49
pub struct PublicKey(pub(crate) ed25519_dalek::VerifyingKey);
50

            
51
impl<'a> From<&'a Keypair> for PublicKey {
52
8185
    fn from(value: &'a Keypair) -> Self {
53
8185
        PublicKey((&value.0).into())
54
8185
    }
55
}
56

            
57
impl ConstantTimeEq for PublicKey {
58
44862
    fn ct_eq(&self, other: &Self) -> Choice {
59
44862
        self.as_bytes().ct_eq(other.as_bytes())
60
44862
    }
61
}
62

            
63
impl PublicKey {
64
    /// Construct a public key from its byte representation.
65
362549
    pub fn from_bytes(bytes: &[u8; 32]) -> Result<Self, signature::Error> {
66
362549
        Ok(PublicKey(ed25519_dalek::VerifyingKey::from_bytes(bytes)?))
67
362549
    }
68

            
69
    /// Return a reference to the byte representation of this public key.
70
381291
    pub fn as_bytes(&self) -> &[u8; 32] {
71
381291
        self.0.as_bytes()
72
381291
    }
73
    /// Return the byte representation of this public key.
74
19746
    pub fn to_bytes(&self) -> [u8; 32] {
75
19746
        self.0.to_bytes()
76
19746
    }
77
    /// Verify a signature using this public key.
78
    ///
79
    /// See [`ed25519_dalek::VerifyingKey::verify`] for more information.
80
137379
    pub fn verify(&self, message: &[u8], signature: &Signature) -> Result<(), signature::Error> {
81
137379
        self.0.verify(message, &signature.0)
82
137379
    }
83
}
84
impl Keypair {
85
    /// Generate a new random ed25519 keypair.
86
6295
    pub fn generate<R: rand_core::Rng + rand_core::CryptoRng>(csprng: &mut R) -> Self {
87
6295
        Self(ed25519_dalek::SigningKey::generate(csprng))
88
6295
    }
89
    /// Construct an ed25519 keypair from the byte representation of its secret key.
90
186
    pub fn from_bytes(bytes: &[u8; 32]) -> Self {
91
186
        Self(ed25519_dalek::SigningKey::from_bytes(bytes))
92
186
    }
93
    /// Return a reference to the byte representation of the secret key in this keypair.
94
12184
    pub fn as_bytes(&self) -> &[u8; 32] {
95
12184
        self.0.as_bytes()
96
12184
    }
97
    /// Return to the byte representation of the secret key in this keypair.
98
373
    pub fn to_bytes(&self) -> [u8; 32] {
99
373
        self.0.to_bytes()
100
373
    }
101
    /// Return the public key in this keypair.
102
128991
    pub fn verifying_key(&self) -> PublicKey {
103
128991
        PublicKey(*self.0.as_ref())
104
128991
    }
105
    /// Verify a signature generated with this keypair.
106
279
    pub fn verify(&self, message: &[u8], signature: &Signature) -> Result<(), signature::Error> {
107
279
        self.0.verify(message, &signature.0)
108
279
    }
109
    /// Sign a message using this keypair.
110
61752
    pub fn sign(&self, message: &[u8]) -> Signature {
111
61752
        Signature(self.0.sign(message))
112
61752
    }
113
}
114
impl Signature {
115
    /// Construct this signature from its byte representation.
116
129549
    pub fn from_bytes(bytes: &[u8; 64]) -> Self {
117
129549
        Self(ed25519_dalek::Signature::from_bytes(bytes))
118
129549
    }
119
    /// Return the byte representation of this signature.
120
80445
    pub fn to_bytes(&self) -> [u8; 64] {
121
80445
        self.0.to_bytes()
122
80445
    }
123
}
124
impl<'a> TryFrom<&'a [u8]> for PublicKey {
125
    type Error = signature::Error;
126

            
127
33108
    fn try_from(value: &'a [u8]) -> Result<Self, Self::Error> {
128
33108
        Ok(Self(ed25519_dalek::VerifyingKey::try_from(value)?))
129
33108
    }
130
}
131
impl<'a> From<&'a [u8; 32]> for Keypair {
132
12462
    fn from(value: &'a [u8; 32]) -> Self {
133
12462
        Self(ed25519_dalek::SigningKey::from(value))
134
12462
    }
135
}
136
impl From<[u8; 64]> for Signature {
137
53755
    fn from(value: [u8; 64]) -> Self {
138
53755
        Signature(value.into())
139
53755
    }
140
}
141
impl<'a> From<&'a [u8; 64]> for Signature {
142
    fn from(value: &'a [u8; 64]) -> Self {
143
        Signature(value.into())
144
    }
145
}
146

            
147
/// The length of an ED25519 identity, in bytes.
148
pub const ED25519_ID_LEN: usize = 32;
149

            
150
/// The length of an ED25519 signature, in bytes.
151
pub const ED25519_SIGNATURE_LEN: usize = 64;
152

            
153
/// A variant of [`Keypair`] containing an [`ExpandedSecretKey`].
154
///
155
/// In the Tor protocol, we use this type for blinded onion service identity keys
156
/// (KS_hs_blind_id).  Since their scalar values are computed, rather than taken
157
/// directly from a
158
/// SHA-512 transformation of a SecretKey, we cannot use the regular `Keypair`
159
/// type.
160
#[allow(clippy::exhaustive_structs)]
161
#[derive(Deftly)]
162
#[derive_deftly(ConstantTimeEq)]
163
pub struct ExpandedKeypair {
164
    /// The secret part of the key.
165
    pub(crate) secret: ExpandedSecretKey,
166
    /// The public part of this key.
167
    ///
168
    /// NOTE: As with [`ed25519_dalek::SigningKey`], this public key _must_ be
169
    /// the public key matching `secret`.  Putting a different public key in
170
    /// here would enable a class of attacks against ed25519 and enable secret
171
    /// key recovery.
172
    pub(crate) public: PublicKey,
173
}
174

            
175
impl ExpandedKeypair {
176
    /// Return the public part of this expanded keypair.
177
70225
    pub fn public(&self) -> &PublicKey {
178
70225
        &self.public
179
70225
    }
180

            
181
    // NOTE: There is deliberately no secret() function.  If we had one, we
182
    // would be exposing an unescorted secret key, which is part of
183
    // ed25519::hazmat.
184

            
185
    /// Compute a signature over a message using this keypair.
186
8569
    pub fn sign(&self, message: &[u8]) -> Signature {
187
        use sha2::Sha512;
188
        // See notes on ExpandedKeypair about why this hazmat is okay to use.
189
8569
        Signature(ed25519_dalek::hazmat::raw_sign::<Sha512>(
190
8569
            &self.secret,
191
8569
            message,
192
8569
            &self.public.0,
193
8569
        ))
194
8569
    }
195

            
196
    /// Return a representation of the secret key in this keypair.
197
    ///
198
    /// (Since it is an expanded secret key, we represent it as its scalar part
199
    /// followed by its hash_prefix.)
200
9692
    pub fn to_secret_key_bytes(&self) -> [u8; 64] {
201
9692
        let mut output = [0_u8; 64];
202
9692
        output[0..32].copy_from_slice(&self.secret.scalar.to_bytes());
203
9692
        output[32..64].copy_from_slice(&self.secret.hash_prefix);
204
9692
        output
205
9692
    }
206

            
207
    /// Reconstruct a key from its byte representation as returned by
208
    /// `to_secret_key_bytes()`.
209
    ///
210
    /// Return None if the input cannot be the output of `to_secret_key_bytes()`.
211
    //
212
    // NOTE: Returning None is a bit silly, but that's what Dalek does.
213
33955
    pub fn from_secret_key_bytes(bytes: [u8; 64]) -> Option<Self> {
214
33955
        let scalar = Option::from(Scalar::from_bytes_mod_order(
215
33955
            bytes[0..32].try_into().expect("wrong length on slice"),
216
33955
        ))?;
217
33955
        let hash_prefix = bytes[32..64].try_into().expect("wrong length on slice");
218
33955
        let secret = ExpandedSecretKey {
219
33955
            scalar,
220
33955
            hash_prefix,
221
33955
        };
222
33955
        let public = PublicKey((&secret).into());
223
33955
        Some(Self { secret, public })
224
33955
    }
225

            
226
    // NOTE: There is deliberately no constructor here that takes a (secret,
227
    // public) pair.  If there were, you could construct a pair with a
228
    // mismatched public key.
229
}
230

            
231
impl<'a> From<&'a Keypair> for ExpandedKeypair {
232
1210
    fn from(kp: &'a Keypair) -> ExpandedKeypair {
233
1210
        ExpandedKeypair {
234
1210
            secret: kp.as_bytes().into(),
235
1210
            public: kp.into(),
236
1210
        }
237
1210
    }
238
}
239

            
240
impl From<ExpandedKeypair> for PublicKey {
241
372
    fn from(ekp: ExpandedKeypair) -> PublicKey {
242
372
        ekp.public
243
372
    }
244
}
245

            
246
/// An unchecked, unvalidated Ed25519 key.
247
///
248
/// This key is an "identity" in the sense that it identifies (up to) one
249
/// Ed25519 key.  It may also represent the identity for a particular entity,
250
/// such as a relay or an onion service.
251
///
252
/// This type is distinct from an Ed25519 [`PublicKey`] for several reasons:
253
///  * We're storing it in a compact format, whereas the public key
254
///    implementation might want an expanded form for more efficient key
255
///    validation.
256
///  * This type hasn't checked whether the bytes here actually _are_ a valid
257
///    Ed25519 public key.
258
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq)]
259
#[cfg_attr(
260
    feature = "memquota-memcost",
261
    derive(Deftly),
262
    derive_deftly(HasMemoryCost)
263
)]
264
pub struct Ed25519Identity {
265
    /// A raw unchecked Ed25519 public key.
266
    id: CtByteArray<ED25519_ID_LEN>,
267
}
268

            
269
impl Ed25519Identity {
270
    /// Construct a new Ed25519 identity from a 32-byte sequence.
271
    ///
272
    /// This might or might not actually be a valid Ed25519 public key.
273
    ///
274
    /// ```
275
    /// use tor_llcrypto::pk::ed25519::{Ed25519Identity, PublicKey};
276
    ///
277
    /// let bytes = b"klsadjfkladsfjklsdafkljasdfsdsd!";
278
    /// let id = Ed25519Identity::new(*bytes);
279
    /// let pk: Result<PublicKey,_> = (&id).try_into();
280
    /// assert!(pk.is_ok());
281
    ///
282
    /// let bytes = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
283
    /// let id = Ed25519Identity::new(*bytes);
284
    /// let pk: Result<PublicKey,_> = (&id).try_into();
285
    /// assert!(pk.is_err());
286
    /// ```
287
5466077
    pub fn new(id: [u8; 32]) -> Self {
288
5466077
        Ed25519Identity { id: id.into() }
289
5466077
    }
290
    /// If `id` is of the correct length, wrap it in an Ed25519Identity.
291
3454300
    pub fn from_bytes(id: &[u8]) -> Option<Self> {
292
3454300
        Some(Ed25519Identity::new(id.try_into().ok()?))
293
3454300
    }
294
    /// Return a reference to the bytes in this key.
295
364002
    pub fn as_bytes(&self) -> &[u8] {
296
364002
        &self.id.as_ref()[..]
297
364002
    }
298
    /// Decode an `Ed25519Identity` from a base64-encoded string.
299
    ///
300
    /// The string must have no padding, spaces, or any extra characters.
301
    // We decode without padding to match the serde deserialize impl.
302
187
    pub fn from_base64(s: &str) -> Option<Self> {
303
187
        let bytes = Base64Unpadded::decode_vec(s).ok()?;
304
187
        Ed25519Identity::from_bytes(&bytes)
305
187
    }
306
}
307

            
308
impl From<[u8; ED25519_ID_LEN]> for Ed25519Identity {
309
1749424
    fn from(id: [u8; ED25519_ID_LEN]) -> Self {
310
1749424
        Ed25519Identity::new(id)
311
1749424
    }
312
}
313

            
314
impl From<Ed25519Identity> for [u8; ED25519_ID_LEN] {
315
33573
    fn from(value: Ed25519Identity) -> Self {
316
33573
        value.id.into()
317
33573
    }
318
}
319

            
320
impl From<PublicKey> for Ed25519Identity {
321
183117
    fn from(pk: PublicKey) -> Self {
322
183117
        (&pk).into()
323
183117
    }
324
}
325

            
326
impl From<&PublicKey> for Ed25519Identity {
327
244218
    fn from(pk: &PublicKey) -> Self {
328
        // This unwrap is safe because the public key is always 32 bytes
329
        // long.
330
244218
        Ed25519Identity::from_bytes(pk.as_bytes()).expect("Ed25519 public key had wrong length?")
331
244218
    }
332
}
333

            
334
impl TryFrom<&Ed25519Identity> for PublicKey {
335
    type Error = ed25519_dalek::SignatureError;
336
272583
    fn try_from(id: &Ed25519Identity) -> Result<PublicKey, Self::Error> {
337
272583
        PublicKey::from_bytes(id.id.as_ref())
338
272583
    }
339
}
340

            
341
impl TryFrom<Ed25519Identity> for PublicKey {
342
    type Error = ed25519_dalek::SignatureError;
343
204693
    fn try_from(id: Ed25519Identity) -> Result<PublicKey, Self::Error> {
344
204693
        (&id).try_into()
345
204693
    }
346
}
347

            
348
impl ConstantTimeEq for Ed25519Identity {
349
    fn ct_eq(&self, other: &Self) -> Choice {
350
        self.id.ct_eq(&other.id)
351
    }
352
}
353

            
354
impl Display for Ed25519Identity {
355
97929
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
356
97929
        write!(f, "{}", Base64Unpadded::encode_string(self.id.as_ref()))
357
97929
    }
358
}
359

            
360
impl Debug for Ed25519Identity {
361
41292
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
362
41292
        write!(f, "Ed25519Identity {{ {} }}", self)
363
41292
    }
364
}
365

            
366
impl safelog::Redactable for Ed25519Identity {
367
    /// Warning: This displays 12 bits of the ed25519 identity, which is
368
    /// enough to narrow down a public relay by a great deal.
369
93
    fn display_redacted(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
370
93
        write_start_redacted(f, &Base64Unpadded::encode_string(self.id.as_ref()), 2, "…")
371
93
    }
372

            
373
    fn debug_redacted(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
374
        write!(f, "Ed25519Identity {{ {} }}", self.redacted())
375
    }
376
}
377

            
378
impl serde::Serialize for Ed25519Identity {
379
18174
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
380
18174
    where
381
18174
        S: serde::Serializer,
382
    {
383
18174
        if serializer.is_human_readable() {
384
18173
            serializer.serialize_str(&Base64Unpadded::encode_string(self.id.as_ref()))
385
        } else {
386
1
            serializer.serialize_bytes(&self.id.as_ref()[..])
387
        }
388
18174
    }
389
}
390

            
391
impl<'de> serde::Deserialize<'de> for Ed25519Identity {
392
418
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
393
418
    where
394
418
        D: serde::Deserializer<'de>,
395
    {
396
418
        if deserializer.is_human_readable() {
397
            /// Helper for deserialization
398
            struct EdIdentityVisitor;
399
            impl<'de> serde::de::Visitor<'de> for EdIdentityVisitor {
400
                type Value = Ed25519Identity;
401
                fn expecting(&self, fmt: &mut std::fmt::Formatter<'_>) -> fmt::Result {
402
                    fmt.write_str("base64-encoded Ed25519 public key")
403
                }
404
416
                fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
405
416
                where
406
416
                    E: serde::de::Error,
407
                {
408
416
                    let bytes = Base64Unpadded::decode_vec(s).map_err(E::custom)?;
409
416
                    Ed25519Identity::from_bytes(&bytes)
410
                        .ok_or_else(|| E::custom("wrong length for Ed25519 public key"))
411
416
                }
412
            }
413

            
414
416
            deserializer.deserialize_str(EdIdentityVisitor)
415
        } else {
416
            /// Helper for deserialization
417
            struct EdIdentityVisitor;
418
            impl<'de> serde::de::Visitor<'de> for EdIdentityVisitor {
419
                type Value = Ed25519Identity;
420
                fn expecting(&self, fmt: &mut std::fmt::Formatter<'_>) -> fmt::Result {
421
                    fmt.write_str("ed25519 public key")
422
                }
423
2
                fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Self::Value, E>
424
2
                where
425
2
                    E: serde::de::Error,
426
                {
427
2
                    Ed25519Identity::from_bytes(bytes)
428
                        .ok_or_else(|| E::custom("wrong length for ed25519 public key"))
429
2
                }
430
            }
431
2
            deserializer.deserialize_bytes(EdIdentityVisitor)
432
        }
433
418
    }
434
}
435

            
436
/// An ed25519 signature, plus the document that it signs and its
437
/// public key.
438
#[derive(Clone, Debug)]
439
#[cfg_attr(
440
    feature = "memquota-memcost",
441
    derive(Deftly),
442
    derive_deftly(HasMemoryCost)
443
)]
444
pub struct ValidatableEd25519Signature {
445
    /// The key that allegedly produced the signature
446
    #[cfg_attr(feature = "memquota-memcost", deftly(has_memory_cost(copy)))]
447
    key: PublicKey,
448
    /// The alleged signature
449
    #[cfg_attr(feature = "memquota-memcost", deftly(has_memory_cost(copy)))]
450
    sig: Signature,
451
    /// The entire body of text that is allegedly signed here.
452
    ///
453
    /// TODO: It's not so good to have this included here; it
454
    /// would be better to have a patch to ed25519_dalek to allow
455
    /// us to pre-hash the signed thing, and just store a digest.
456
    /// We can't use that with the 'prehash' variant of ed25519,
457
    /// since that has different constants.
458
    entire_text_of_signed_thing: Vec<u8>,
459
}
460

            
461
impl ValidatableEd25519Signature {
462
    /// Create a new ValidatableEd25519Signature
463
71891
    pub fn new(key: PublicKey, sig: Signature, text: &[u8]) -> Self {
464
71891
        ValidatableEd25519Signature {
465
71891
            key,
466
71891
            sig,
467
71891
            entire_text_of_signed_thing: text.into(),
468
71891
        }
469
71891
    }
470

            
471
    /// View the interior of this signature object.
472
14880
    pub(crate) fn as_parts(&self) -> (&PublicKey, &Signature, &[u8]) {
473
14880
        (&self.key, &self.sig, &self.entire_text_of_signed_thing[..])
474
14880
    }
475

            
476
    /// Return a reference to the underlying Signature.
477
558
    pub fn signature(&self) -> &Signature {
478
558
        &self.sig
479
558
    }
480
}
481

            
482
impl super::ValidatableSignature for ValidatableEd25519Signature {
483
45572
    fn is_valid(&self) -> bool {
484
45572
        self.key
485
45572
            .verify(&self.entire_text_of_signed_thing[..], &self.sig)
486
45572
            .is_ok()
487
45572
    }
488

            
489
57660
    fn as_ed25519(&self) -> Option<&ValidatableEd25519Signature> {
490
57660
        Some(self)
491
57660
    }
492
}
493

            
494
/// Perform a batch verification operation on the provided signatures
495
///
496
/// Return `true` if _every_ signature is valid; otherwise return `false`.
497
///
498
/// Note that the mathematics for batch validation are slightly
499
/// different than those for normal one-signature validation.  Because
500
/// of this, it is possible for an ostensible signature that passes
501
/// one validation algorithm might fail the other.  (Well-formed
502
/// signatures generated by a correct Ed25519 implementation will
503
/// always pass both kinds of validation, and an attacker should not
504
/// be able to forge a signature that passes either kind.)
505
49290
pub fn validate_batch(sigs: &[&ValidatableEd25519Signature]) -> bool {
506
    use crate::pk::ValidatableSignature;
507
49290
    if sigs.is_empty() {
508
        // ed25519_dalek has nonzero cost for a batch-verification of
509
        // zero sigs.
510
1488
        true
511
47802
    } else if sigs.len() == 1 {
512
        // Validating one signature in the traditional way is faster.
513
43710
        sigs[0].is_valid()
514
    } else {
515
4092
        let mut ed_msgs = Vec::new();
516
4092
        let mut ed_sigs = Vec::new();
517
4092
        let mut ed_pks = Vec::new();
518
4092
        for ed_sig in sigs {
519
14880
            let (pk, sig, msg) = ed_sig.as_parts();
520
14880
            ed_sigs.push(sig.0);
521
14880
            ed_pks.push(pk.0);
522
14880
            ed_msgs.push(msg);
523
        }
524
4092
        ed25519_dalek::verify_batch(&ed_msgs[..], &ed_sigs[..], &ed_pks[..]).is_ok()
525
    }
526
49290
}
527

            
528
/// An object that has an Ed25519 [`PublicKey`].
529
pub trait Ed25519PublicKey {
530
    /// Get the Ed25519 [`PublicKey`].
531
    fn public_key(&self) -> PublicKey;
532
}
533

            
534
impl Ed25519PublicKey for Keypair {
535
59799
    fn public_key(&self) -> PublicKey {
536
59799
        Keypair::verifying_key(self)
537
59799
    }
538
}
539

            
540
impl Ed25519PublicKey for ExpandedKeypair {
541
    fn public_key(&self) -> PublicKey {
542
        self.public
543
    }
544
}
545

            
546
/// An object that can generate Ed25519 signatures.
547
pub trait Ed25519SigningKey {
548
    /// Sign a message with this key.
549
    fn sign(&self, message: &[u8]) -> Signature;
550
}
551

            
552
impl Ed25519SigningKey for Keypair {
553
49290
    fn sign(&self, message: &[u8]) -> Signature {
554
49290
        Keypair::sign(self, message)
555
49290
    }
556
}
557
impl Ed25519SigningKey for ExpandedKeypair {
558
651
    fn sign(&self, message: &[u8]) -> Signature {
559
651
        ExpandedKeypair::sign(self, message)
560
651
    }
561
}
562

            
563
#[cfg(test)]
564
mod test {
565
    // @@ begin test lint list maintained by maint/add_warning @@
566
    #![allow(clippy::bool_assert_comparison)]
567
    #![allow(clippy::clone_on_copy)]
568
    #![allow(clippy::dbg_macro)]
569
    #![allow(clippy::mixed_attributes_style)]
570
    #![allow(clippy::print_stderr)]
571
    #![allow(clippy::print_stdout)]
572
    #![allow(clippy::single_char_pattern)]
573
    #![allow(clippy::unwrap_used)]
574
    #![allow(clippy::unchecked_time_subtraction)]
575
    #![allow(clippy::useless_vec)]
576
    #![allow(clippy::needless_pass_by_value)]
577
    #![allow(clippy::string_slice)] // See arti#2571
578
    //! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
579

            
580
    use super::*;
581

            
582
    #[test]
583
    fn ed_from_base64() {
584
        let id =
585
            Ed25519Identity::from_base64("qpL/LxLYVEXghU76iG3LsSI/UW7MBpIROZK0AB18560").unwrap();
586

            
587
        assert_eq!(
588
            id,
589
            Ed25519Identity::from([
590
                0xaa, 0x92, 0xff, 0x2f, 0x12, 0xd8, 0x54, 0x45, 0xe0, 0x85, 0x4e, 0xfa, 0x88, 0x6d,
591
                0xcb, 0xb1, 0x22, 0x3f, 0x51, 0x6e, 0xcc, 0x06, 0x92, 0x11, 0x39, 0x92, 0xb4, 0x00,
592
                0x1d, 0x7c, 0xe7, 0xad
593
            ]),
594
        );
595
    }
596
}