mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Expand const fn support (#494)
Does a pass on adding `const` to methods where it's possible.
This commit is contained in:
parent
6a51f4fa40
commit
8c2f545d91
4 changed files with 12 additions and 11 deletions
|
|
@ -176,12 +176,12 @@ impl Debug for CompressedEdwardsY {
|
|||
|
||||
impl CompressedEdwardsY {
|
||||
/// View this `CompressedEdwardsY` as an array of bytes.
|
||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
||||
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Copy this `CompressedEdwardsY` to an array of bytes.
|
||||
pub fn to_bytes(&self) -> [u8; 32] {
|
||||
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||
self.0
|
||||
}
|
||||
|
||||
|
|
@ -481,7 +481,7 @@ impl EdwardsPoint {
|
|||
/// coordinates to projective coordinates.
|
||||
///
|
||||
/// Free.
|
||||
pub(crate) fn as_projective(&self) -> ProjectivePoint {
|
||||
pub(crate) const fn as_projective(&self) -> ProjectivePoint {
|
||||
ProjectivePoint {
|
||||
X: self.X,
|
||||
Y: self.Y,
|
||||
|
|
|
|||
|
|
@ -119,12 +119,12 @@ impl Zeroize for MontgomeryPoint {
|
|||
|
||||
impl MontgomeryPoint {
|
||||
/// View this `MontgomeryPoint` as an array of bytes.
|
||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
||||
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Convert this `MontgomeryPoint` to an array of bytes.
|
||||
pub fn to_bytes(&self) -> [u8; 32] {
|
||||
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||
self.0
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,12 +231,12 @@ impl ConstantTimeEq for CompressedRistretto {
|
|||
|
||||
impl CompressedRistretto {
|
||||
/// Copy the bytes of this `CompressedRistretto`.
|
||||
pub fn to_bytes(&self) -> [u8; 32] {
|
||||
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// View this `CompressedRistretto` as an array of bytes.
|
||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
||||
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,8 +226,9 @@ pub struct Scalar {
|
|||
///
|
||||
/// This ensures that there is room for a carry bit when computing a NAF representation.
|
||||
//
|
||||
// XXX This is pub(crate) so we can write literal constants. If const fns were stable, we could
|
||||
// make the Scalar constructors const fns and use those instead.
|
||||
// XXX This is pub(crate) so we can write literal constants.
|
||||
// Alternatively we could make the Scalar constructors `const fn`s and use those instead.
|
||||
// See dalek-cryptography/curve25519-dalek#493
|
||||
pub(crate) bytes: [u8; 32],
|
||||
}
|
||||
|
||||
|
|
@ -688,7 +689,7 @@ impl Scalar {
|
|||
///
|
||||
/// assert!(s.to_bytes() == [0u8; 32]);
|
||||
/// ```
|
||||
pub fn to_bytes(&self) -> [u8; 32] {
|
||||
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||
self.bytes
|
||||
}
|
||||
|
||||
|
|
@ -703,7 +704,7 @@ impl Scalar {
|
|||
///
|
||||
/// assert!(s.as_bytes() == &[0u8; 32]);
|
||||
/// ```
|
||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
||||
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||
&self.bytes
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue