ssi-multicodec 0.2.0

Implementation of the Multicodec specification for the ssi library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::borrow::Cow;

use crate::{Codec, Error, P384_PUB};

impl Codec for p384::PublicKey {
    const CODEC: u64 = P384_PUB;

    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
        Self::from_sec1_bytes(bytes).map_err(|_| Error::InvalidData)
    }

    fn to_bytes(&self) -> Cow<[u8]> {
        use p384::elliptic_curve::sec1::ToEncodedPoint;
        Cow::Owned(self.to_encoded_point(true).as_bytes().to_vec())
    }
}