mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
Add example code for Scalar.to_bytes() and Scalar.as_bytes().
This commit is contained in:
parent
ff16e93102
commit
74a28559c4
1 changed files with 21 additions and 1 deletions
|
|
@ -533,11 +533,31 @@ impl Scalar {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this `Scalar` to its underlying sequence of bytes.
|
/// Convert this `Scalar` to its underlying sequence of bytes.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use curve25519_dalek::scalar::Scalar;
|
||||||
|
///
|
||||||
|
/// let s: Scalar = Scalar::zero();
|
||||||
|
///
|
||||||
|
/// assert!(s.to_bytes() == [0u8; 32]);
|
||||||
|
/// ```
|
||||||
pub fn to_bytes(&self) -> [u8; 32] {
|
pub fn to_bytes(&self) -> [u8; 32] {
|
||||||
self.bytes
|
self.bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
/// View this `Scalar` as a sequence of bytes.
|
/// View this `Scalar` as its underlying sequence of bytes.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use curve25519_dalek::scalar::Scalar;
|
||||||
|
///
|
||||||
|
/// let s: Scalar = Scalar::zero();
|
||||||
|
///
|
||||||
|
/// assert!(s.as_bytes() == &[0u8; 32]);
|
||||||
|
/// ```
|
||||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
pub fn as_bytes(&self) -> &[u8; 32] {
|
||||||
&self.bytes
|
&self.bytes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue