Implement --identity command
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
use bech32::ToBase32;
|
||||
use elliptic_curve::sec1::EncodedPoint;
|
||||
use p256::NistP256;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
|
||||
use crate::RECIPIENT_PREFIX;
|
||||
|
||||
pub(crate) const TAG_BYTES: usize = 4;
|
||||
|
||||
/// Wrapper around a compressed secp256r1 curve point.
|
||||
#[derive(Clone)]
|
||||
pub struct Recipient(EncodedPoint<NistP256>);
|
||||
@@ -43,4 +47,9 @@ impl Recipient {
|
||||
pub(crate) fn as_bytes(&self) -> &[u8] {
|
||||
self.0.as_bytes()
|
||||
}
|
||||
|
||||
pub(crate) fn tag(&self) -> [u8; TAG_BYTES] {
|
||||
let tag = Sha256::digest(self.to_string().as_bytes());
|
||||
(&tag[0..TAG_BYTES]).try_into().expect("length is correct")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user