Skip to content

signature: simplify encoding trait #1149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions signature/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Encoding support.

use crate::{Error, Result};
use crate::Error;

#[cfg(feature = "alloc")]
use alloc::{boxed::Box, vec::Vec};
use alloc::vec::Vec;

/// Support for decoding/encoding signatures as bytes.
pub trait SignatureEncoding:
Expand All @@ -12,11 +12,6 @@ pub trait SignatureEncoding:
/// Byte representation of a signature.
type Repr: 'static + AsRef<[u8]> + Clone + Send + Sync;

/// Decode signature from its byte representation.
fn from_bytes(bytes: &Self::Repr) -> Result<Self> {
Self::try_from(bytes.as_ref())
}

/// Encode signature as its byte representation.
fn to_bytes(&self) -> Self::Repr {
self.clone().into()
Expand All @@ -28,11 +23,4 @@ pub trait SignatureEncoding:
fn to_vec(&self) -> Vec<u8> {
self.to_bytes().as_ref().to_vec()
}

/// Encode the signature as a boxed byte slice.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn to_boxed_slice(&self) -> Box<[u8]> {
self.to_vec().into_boxed_slice()
}
}