mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-08 20:40:32 +00:00
Run rustfmt on src/signature.rs.
This commit is contained in:
parent
144e87bfc8
commit
a141863542
1 changed files with 29 additions and 13 deletions
|
|
@ -14,14 +14,14 @@ use core::fmt::Debug;
|
||||||
use curve25519_dalek::edwards::CompressedEdwardsY;
|
use curve25519_dalek::edwards::CompressedEdwardsY;
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Serializer, Deserializer};
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::de::Error as SerdeError;
|
use serde::de::Error as SerdeError;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::de::Visitor;
|
use serde::de::Visitor;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserializer, Serializer};
|
||||||
|
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
|
@ -45,7 +45,7 @@ pub struct Signature {
|
||||||
/// This digest is then interpreted as a `Scalar` and reduced into an
|
/// This digest is then interpreted as a `Scalar` and reduced into an
|
||||||
/// element in ℤ/lℤ. The scalar is then multiplied by the distinguished
|
/// element in ℤ/lℤ. The scalar is then multiplied by the distinguished
|
||||||
/// basepoint to produce `R`, and `EdwardsPoint`.
|
/// basepoint to produce `R`, and `EdwardsPoint`.
|
||||||
pub (crate) R: CompressedEdwardsY,
|
pub(crate) R: CompressedEdwardsY,
|
||||||
|
|
||||||
/// `s` is a `Scalar`, formed by using an hash function with 512-bits output
|
/// `s` is a `Scalar`, formed by using an hash function with 512-bits output
|
||||||
/// to produce the digest of:
|
/// to produce the digest of:
|
||||||
|
|
@ -56,11 +56,13 @@ pub struct Signature {
|
||||||
///
|
///
|
||||||
/// This digest is then interpreted as a `Scalar` and reduced into an
|
/// This digest is then interpreted as a `Scalar` and reduced into an
|
||||||
/// element in ℤ/lℤ.
|
/// element in ℤ/lℤ.
|
||||||
pub (crate) s: Scalar,
|
pub(crate) s: Scalar,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Signature {
|
impl Clone for Signature {
|
||||||
fn clone(&self) -> Self { *self }
|
fn clone(&self) -> Self {
|
||||||
|
*self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Signature {
|
impl Debug for Signature {
|
||||||
|
|
@ -84,8 +86,10 @@ impl Signature {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_bytes(bytes: &[u8]) -> Result<Signature, SignatureError> {
|
pub fn from_bytes(bytes: &[u8]) -> Result<Signature, SignatureError> {
|
||||||
if bytes.len() != SIGNATURE_LENGTH {
|
if bytes.len() != SIGNATURE_LENGTH {
|
||||||
return Err(SignatureError(InternalError::BytesLengthError{
|
return Err(SignatureError(InternalError::BytesLengthError {
|
||||||
name: "Signature", length: SIGNATURE_LENGTH }));
|
name: "Signature",
|
||||||
|
length: SIGNATURE_LENGTH,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
let mut lower: [u8; 32] = [0u8; 32];
|
let mut lower: [u8; 32] = [0u8; 32];
|
||||||
let mut upper: [u8; 32] = [0u8; 32];
|
let mut upper: [u8; 32] = [0u8; 32];
|
||||||
|
|
@ -97,20 +101,29 @@ impl Signature {
|
||||||
return Err(SignatureError(InternalError::ScalarFormatError));
|
return Err(SignatureError(InternalError::ScalarFormatError));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Signature{ R: CompressedEdwardsY(lower), s: Scalar::from_bits(upper) })
|
Ok(Signature {
|
||||||
|
R: CompressedEdwardsY(lower),
|
||||||
|
s: Scalar::from_bits(upper),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
impl Serialize for Signature {
|
impl Serialize for Signature {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
serializer.serialize_bytes(&self.to_bytes()[..])
|
serializer.serialize_bytes(&self.to_bytes()[..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
impl<'d> Deserialize<'d> for Signature {
|
impl<'d> Deserialize<'d> for Signature {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'d> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'d>,
|
||||||
|
{
|
||||||
struct SignatureVisitor;
|
struct SignatureVisitor;
|
||||||
|
|
||||||
impl<'d> Visitor<'d> for SignatureVisitor {
|
impl<'d> Visitor<'d> for SignatureVisitor {
|
||||||
|
|
@ -120,7 +133,10 @@ impl<'d> Deserialize<'d> for Signature {
|
||||||
formatter.write_str("An ed25519 signature as 64 bytes, as specified in RFC8032.")
|
formatter.write_str("An ed25519 signature as 64 bytes, as specified in RFC8032.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Signature, E> where E: SerdeError{
|
fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Signature, E>
|
||||||
|
where
|
||||||
|
E: SerdeError,
|
||||||
|
{
|
||||||
Signature::from_bytes(bytes).or(Err(SerdeError::invalid_length(bytes.len(), &self)))
|
Signature::from_bytes(bytes).or(Err(SerdeError::invalid_length(bytes.len(), &self)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue