#[repr(C)]pub struct Signature { /* private fields */ }
Expand description
Ed25519 signature.
Implementations§
source§impl Signature
impl Signature
sourcepub fn from_bytes(bytes: &SignatureBytes) -> Result<Self>
pub fn from_bytes(bytes: &SignatureBytes) -> Result<Self>
Parse an Ed25519 signature from a byte slice.
Examples found in repository?
More examples
src/serde.rs (line 57)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct ByteArrayVisitor;
impl<'de> de::Visitor<'de> for ByteArrayVisitor {
type Value = [u8; Signature::BYTE_SIZE];
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("bytestring of length 64")
}
fn visit_seq<A>(self, mut seq: A) -> Result<[u8; Signature::BYTE_SIZE], A::Error>
where
A: de::SeqAccess<'de>,
{
use de::Error;
let mut arr = [0u8; Signature::BYTE_SIZE];
for (i, byte) in arr.iter_mut().enumerate() {
*byte = seq
.next_element()?
.ok_or_else(|| Error::invalid_length(i, &self))?;
}
Ok(arr)
}
}
let bytes = deserializer.deserialize_tuple(Signature::BYTE_SIZE, ByteArrayVisitor)?;
Self::from_bytes(&bytes).map_err(de::Error::custom)
}
}
#[cfg(feature = "serde_bytes")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde_bytes")))]
impl serde_bytes::Serialize for Signature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_bytes(&self.to_bytes())
}
}
#[cfg(feature = "serde_bytes")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde_bytes")))]
impl<'de> serde_bytes::Deserialize<'de> for Signature {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: de::Deserializer<'de>,
{
struct ByteArrayVisitor;
impl<'de> de::Visitor<'de> for ByteArrayVisitor {
type Value = SignatureBytes;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("bytestring of length 64")
}
fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Self::Value, E>
where
E: de::Error,
{
use de::Error;
bytes
.try_into()
.map_err(|_| Error::invalid_length(bytes.len(), &self))
}
}
let bytes = deserializer.deserialize_bytes(ByteArrayVisitor)?;
Self::from_bytes(&bytes).map_err(de::Error::custom)
}
sourcepub fn from_components(R: ComponentBytes, s: ComponentBytes) -> Result<Self>
pub fn from_components(R: ComponentBytes, s: ComponentBytes) -> Result<Self>
Parse an Ed25519 signature from its R
and s
components.
sourcepub fn r_bytes(&self) -> &ComponentBytes
pub fn r_bytes(&self) -> &ComponentBytes
Bytes for the R
component of a signature.
sourcepub fn s_bytes(&self) -> &ComponentBytes
pub fn s_bytes(&self) -> &ComponentBytes
Bytes for the s
component of a signature.
sourcepub fn to_bytes(&self) -> SignatureBytes
pub fn to_bytes(&self) -> SignatureBytes
Return the inner byte array.
Examples found in repository?
src/lib.rs (line 352)
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
pub fn to_vec(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}
impl SignatureEncoding for Signature {
type Repr = SignatureBytes;
fn to_bytes(&self) -> SignatureBytes {
self.to_bytes()
}
}
impl From<Signature> for SignatureBytes {
fn from(sig: Signature) -> SignatureBytes {
sig.to_bytes()
}
}
impl From<&Signature> for SignatureBytes {
fn from(sig: &Signature) -> SignatureBytes {
sig.to_bytes()
}
More examples
src/serde.rs (line 17)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
fn serialize<S: ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
use ser::SerializeTuple;
let mut seq = serializer.serialize_tuple(Signature::BYTE_SIZE)?;
for byte in self.to_bytes() {
seq.serialize_element(&byte)?;
}
seq.end()
}
}
// serde lacks support for deserializing arrays larger than 32-bytes
// see: <https://github.com/serde-rs/serde/issues/631>
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> Deserialize<'de> for Signature {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct ByteArrayVisitor;
impl<'de> de::Visitor<'de> for ByteArrayVisitor {
type Value = [u8; Signature::BYTE_SIZE];
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("bytestring of length 64")
}
fn visit_seq<A>(self, mut seq: A) -> Result<[u8; Signature::BYTE_SIZE], A::Error>
where
A: de::SeqAccess<'de>,
{
use de::Error;
let mut arr = [0u8; Signature::BYTE_SIZE];
for (i, byte) in arr.iter_mut().enumerate() {
*byte = seq
.next_element()?
.ok_or_else(|| Error::invalid_length(i, &self))?;
}
Ok(arr)
}
}
let bytes = deserializer.deserialize_tuple(Signature::BYTE_SIZE, ByteArrayVisitor)?;
Self::from_bytes(&bytes).map_err(de::Error::custom)
}
}
#[cfg(feature = "serde_bytes")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde_bytes")))]
impl serde_bytes::Serialize for Signature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_bytes(&self.to_bytes())
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for Signature
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Signature
Available on crate feature
serde
only.source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
source§impl<'de> Deserialize<'de> for Signature
Available on crate feature serde_bytes
only.
impl<'de> Deserialize<'de> for Signature
Available on crate feature
serde_bytes
only.fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl From<&Signature> for SignatureBytes
impl From<&Signature> for SignatureBytes
source§fn from(sig: &Signature) -> SignatureBytes
fn from(sig: &Signature) -> SignatureBytes
Converts to this type from the input type.
source§impl From<Signature> for SignatureBytes
impl From<Signature> for SignatureBytes
source§fn from(sig: Signature) -> SignatureBytes
fn from(sig: Signature) -> SignatureBytes
Converts to this type from the input type.
source§impl FromStr for Signature
impl FromStr for Signature
Decode a signature from hexadecimal.
Upper and lower case hexadecimal are both accepted, however mixed case is rejected.