Skip to main content

PublicKey

Struct PublicKey 

Source
pub struct PublicKey<L: SecurityLevel = Level1> { /* private fields */ }
Expand description

SQIsign public key: a Montgomery curve coefficient plus a torsion hint byte.

Wire size: 65 bytes (Level 1), 97 bytes (Level 3), 129 bytes (Level 5).

§Verify a signature

Use pk.verify(msg, &sig) via the Verifier trait. It accepts any signature type: Signature, ExpandedSignature, CompressedSignature, or AnySignature.

use hex_literal::hex;
use sqisign_verify::{PublicKey, Signature, Verifier};

let pk_bytes = hex!(
    "07CCD21425136F6E865E497D2D4D208F0054AD81372066E817480787AAF7B202"
    "9550C89E892D618CE3230F23510BFBE68FCCDDAEA51DB1436B462ADFAF008A01"
    "0B"
);
let sig_bytes = hex!(
    "84228651F271B0F39F2F19F2E8718F31ED3365AC9E5CB303AFE663D0CFC11F04"
    "55D891B0CA6C7E653F9BA2667730BB77BEFE1B1A31828404284AF8FD7BAACC01"
    "0001D974B5CA671FF65708D8B462A5A84A1443EE9B5FED7218767C9D85CEED04"
    "DB0A69A2F6EC3BE835B3B2624B9A0DF68837AD00BCACC27D1EC806A448402674"
    "71D86EFF3447018ADB0A6551EE8322AB30010202"
);
let msg = hex!(
    "D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556A"
    "C8"
);

let pk: PublicKey = PublicKey::from_bytes(&pk_bytes)?;
let sig: Signature = Signature::from_bytes(&sig_bytes)?;
pk.verify(&msg, &sig)?;

§Decode and re-encode

use hex_literal::hex;
use sqisign_verify::PublicKey;

let pk_bytes = hex!(
    "07CCD21425136F6E865E497D2D4D208F0054AD81372066E817480787AAF7B202"
    "9550C89E892D618CE3230F23510BFBE68FCCDDAEA51DB1436B462ADFAF008A01"
    "0B"
);
let pk: PublicKey = PublicKey::from_bytes(&pk_bytes)?;
assert_eq!(pk_bytes, pk.to_bytes().as_slice());

§Display

Display prints the wire-format bytes as lowercase hex:

let hex_str = format!("{pk}");
assert!(hex_str.starts_with("07ccd214"));

Implementations§

Source§

impl<L: FpBackend> PublicKey<L>

Source

pub fn curve(&self) -> &EcCurve<L>

Source

pub fn hint_pk(&self) -> u8

Source§

impl<L: FpBackend> PublicKey<L>

Source

pub fn to_bytes(&self) -> Array<u8, L::PkLen>

Encode a public key to bytes (wire format).

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
where L: LevelPrecomp,

Decode a public key from bytes (wire format).

Rejects non-canonical hint_pk values to ensure each logical public key has exactly one valid wire encoding.

Trait Implementations§

Source§

impl<L: Clone + SecurityLevel> Clone for PublicKey<L>

Source§

fn clone(&self) -> PublicKey<L>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: FpBackend> Debug for PublicKey<L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: FpBackend> Default for PublicKey<L>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<L: FpBackend> Display for PublicKey<L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: FpBackend + LevelPrecomp> TryFrom<&[u8]> for PublicKey<L>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L: FpBackend + LevelPrecomp> Verifier<AnySignature<L>> for PublicKey<L>

Source§

fn verify(&self, msg: &[u8], sig: &AnySignature<L>) -> Result<(), Error>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
Source§

impl<L: FpBackend + LevelPrecomp> Verifier<CompressedSignature<L>> for PublicKey<L>

Source§

fn verify(&self, msg: &[u8], sig: &CompressedSignature<L>) -> Result<(), Error>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
Source§

impl<L: FpBackend + LevelPrecomp> Verifier<ExpandedSignature<L>> for PublicKey<L>

Source§

fn verify(&self, msg: &[u8], sig: &ExpandedSignature<L>) -> Result<(), Error>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
Source§

impl<L: FpBackend + LevelPrecomp> Verifier<Signature<L>> for PublicKey<L>

Source§

fn verify(&self, msg: &[u8], sig: &Signature<L>) -> Result<(), Error>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.