pub struct SigningKey(/* private fields */);Expand description
An ed25519 private key. Used for signing messages.
Implementations§
Source§impl SigningKey
impl SigningKey
pub const LEN: usize = 32usize
pub fn from_bytes(bytes: &[u8; 32]) -> Self
pub fn into_inner(self) -> SigningKey
Sourcepub fn random() -> Self
pub fn random() -> Self
Generates a new random SigningKey.
Sourcepub fn random_from_rng<R: CryptoRngCore + ?Sized>(rng: &mut R) -> Self
pub fn random_from_rng<R: CryptoRngCore + ?Sized>(rng: &mut R) -> Self
Generates a new random SigningKey from the given RNG.
Sourcepub fn verifying_key(&self) -> VerifyingKey
pub fn verifying_key(&self) -> VerifyingKey
Gets the public VerifyingKey that corresponds to this private SigningKey.
Sourcepub fn sign(&self, message: impl AsRef<[u8]>, context: Context<'_>) -> Signature
pub fn sign(&self, message: impl AsRef<[u8]>, context: Context<'_>) -> Signature
Signs message using the ed25519ph algorithm.
§Example
use did_simple::crypto::{Context, ed25519::{SigningKey, VerifyingKey}};
let signing_key = SigningKey::random();
let verifying_key = signing_key.verifying_key();
const CTX: Context = Context::from_bytes("MySuperCoolProtocol".as_bytes());
let msg = "everyone can read and verify this message";
let sig = signing_key.sign(msg, CTX);
assert!(verifying_key.verify(msg, CTX, &sig).is_ok());Sourcepub fn sign_digest(
&self,
message_digest: Sha512,
context: Context<'_>,
) -> Signature
pub fn sign_digest( &self, message_digest: Sha512, context: Context<'_>, ) -> Signature
Same as sign, but allows you to populate message_digest separately
from signing.
This can be useful if for example, it is undesirable to buffer the message into a single slice, or the message is being streamed asynchronously. You can instead update the digest chunk by chunk, and pass the digest in after you are done reading all the data.
§Example
use did_simple::crypto::{Context, ed25519::{Sha512, Digest, SigningKey, VerifyingKey}};
let signing_key = SigningKey::random();
let verifying_key = signing_key.verifying_key();
const CTX: Context = Context::from_bytes("MySuperCoolProtocol".as_bytes());
let mut digest = Sha512::new();
digest.update("this is ");
digest.update("my message");
let sig = signing_key.sign_digest(digest, CTX);
assert!(verifying_key.verify("this is my message", CTX, &sig).is_ok());Trait Implementations§
Auto Trait Implementations§
impl Freeze for SigningKey
impl RefUnwindSafe for SigningKey
impl Send for SigningKey
impl Sync for SigningKey
impl Unpin for SigningKey
impl UnwindSafe for SigningKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more