File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,32 @@ impl SecretKey {
5959 PublicKey ( MontgomeryPoint :: mul_base ( & self . scalar ) )
6060 }
6161
62+ /// Borrows [`SecretKey`] as bytes.
63+ ///
64+ /// # ⚠️Warning
65+ ///
66+ /// The bytes are secret key material. Please treat them with
67+ /// the care they deserve!
68+ ///
69+ /// # `Scalar` conversion notes
70+ ///
71+ /// If you are using the `From<Scalar>` impl on [`SecretKey`] (as opposed
72+ /// to using [`SecretKey::from_bytes`] or one of the other methods that
73+ /// decodes a secret key from bytes), this method will return the same
74+ /// value as `Scalar::to_bytes`, which may reflect "clamping" if it was
75+ /// applied to the original `Scalar`.
76+ ///
77+ /// In such cases, it may be undesirable to call this method, since such a
78+ /// value may not reflect the original scalar prior to clamping. We suggest
79+ /// you don't call this method when using `From<Scalar>` unless you know
80+ /// what you're doing.
81+ ///
82+ /// Calling [`SecretKey::to_scalar`] can be used to safely round-trip the
83+ /// scalar value in such cases.
84+ pub fn as_bytes ( & self ) -> & [ u8 ; KEY_SIZE ] {
85+ & self . bytes
86+ }
87+
6288 /// Serialize [`SecretKey`] to bytes.
6389 ///
6490 /// # ⚠️Warning
You can’t perform that action at this time.
0 commit comments