-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make PeerDid generic over numalgo (#887)
Make PeerDid generic over numalgo (#887) Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
- Loading branch information
Showing
24 changed files
with
639 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::{error::DidPeerError, numalgos::numalgo2, numalgos::numalgo3}; | ||
use did_doc::schema::did_doc::DidDocument; | ||
use did_doc_sov::extra_fields::ExtraFieldsSov; | ||
|
||
use super::{ | ||
numalgos::{numalgo2::Numalgo2, numalgo3::Numalgo3}, | ||
peer_did::PeerDid, | ||
}; | ||
|
||
pub fn generate_numalgo2(did_document: DidDocument<ExtraFieldsSov>) -> Result<PeerDid<Numalgo2>, DidPeerError> { | ||
numalgo2::generate_numalgo2(did_document) | ||
} | ||
|
||
pub fn generate_numalgo3(did_document: DidDocument<ExtraFieldsSov>) -> Result<PeerDid<Numalgo3>, DidPeerError> { | ||
numalgo3::generate_numalgo3(generate_numalgo2(did_document)?.did()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
mod numalgo; | ||
mod peer_did; | ||
mod regex; | ||
mod transform; | ||
pub mod generate; | ||
pub mod numalgos; | ||
pub mod peer_did; | ||
|
||
pub use numalgo::Numalgo; | ||
pub use peer_did::PeerDid; | ||
mod parse; | ||
mod regex; | ||
mod validate; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pub mod numalgo0; | ||
pub mod numalgo1; | ||
pub mod numalgo2; | ||
pub mod numalgo3; | ||
|
||
pub(super) mod traits; | ||
|
||
use std::fmt::Display; | ||
|
||
use numalgo0::Numalgo0; | ||
use numalgo1::Numalgo1; | ||
use numalgo2::Numalgo2; | ||
use numalgo3::Numalgo3; | ||
|
||
use crate::error::DidPeerError; | ||
|
||
use self::traits::Numalgo; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub enum NumalgoKind { | ||
InceptionKeyWithoutDoc(Numalgo0), | ||
GenesisDoc(Numalgo1), | ||
MultipleInceptionKeys(Numalgo2), | ||
DidShortening(Numalgo3), | ||
} | ||
|
||
impl Display for NumalgoKind { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
NumalgoKind::InceptionKeyWithoutDoc(_) => Numalgo0::NUMALGO_CHAR.fmt(f), | ||
NumalgoKind::GenesisDoc(_) => Numalgo1::NUMALGO_CHAR.fmt(f), | ||
NumalgoKind::MultipleInceptionKeys(_) => Numalgo2::NUMALGO_CHAR.fmt(f), | ||
NumalgoKind::DidShortening(_) => Numalgo3::NUMALGO_CHAR.fmt(f), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<char> for NumalgoKind { | ||
type Error = DidPeerError; | ||
|
||
fn try_from(value: char) -> Result<Self, Self::Error> { | ||
match value { | ||
Numalgo0::NUMALGO_CHAR => Ok(NumalgoKind::InceptionKeyWithoutDoc(Numalgo0)), | ||
Numalgo1::NUMALGO_CHAR => Ok(NumalgoKind::GenesisDoc(Numalgo1)), | ||
Numalgo2::NUMALGO_CHAR => Ok(NumalgoKind::MultipleInceptionKeys(Numalgo2)), | ||
Numalgo3::NUMALGO_CHAR => Ok(NumalgoKind::DidShortening(Numalgo3)), | ||
c @ _ => Err(DidPeerError::InvalidNumalgoCharacter(c)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::traits::Numalgo; | ||
|
||
#[derive(Clone, Copy, Default, Debug, PartialEq)] | ||
pub struct Numalgo0; | ||
|
||
impl Numalgo for Numalgo0 { | ||
const NUMALGO_CHAR: char = '0'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::traits::Numalgo; | ||
|
||
#[derive(Clone, Copy, Default, Debug, PartialEq)] | ||
pub struct Numalgo1; | ||
|
||
impl Numalgo for Numalgo1 { | ||
const NUMALGO_CHAR: char = '1'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use did_doc::schema::did_doc::DidDocument; | ||
use did_doc_sov::extra_fields::ExtraFieldsSov; | ||
use did_parser::Did; | ||
|
||
use crate::{ | ||
error::DidPeerError, | ||
numalgos::{numalgo2::resolve_numalgo2, numalgo3::generate_numalgo3}, | ||
peer_did::peer_did::PeerDid, | ||
peer_did_resolver::options::PublicKeyEncoding, | ||
}; | ||
|
||
use super::{ | ||
numalgo3::Numalgo3, | ||
traits::{Numalgo, ResolvableNumalgo, ToNumalgo3}, | ||
}; | ||
|
||
#[derive(Clone, Copy, Default, Debug, PartialEq)] | ||
pub struct Numalgo2; | ||
|
||
impl Numalgo for Numalgo2 { | ||
const NUMALGO_CHAR: char = '2'; | ||
} | ||
|
||
impl ResolvableNumalgo for Numalgo2 { | ||
fn resolve( | ||
&self, | ||
did: &Did, | ||
public_key_encoding: PublicKeyEncoding, | ||
) -> Result<DidDocument<ExtraFieldsSov>, DidPeerError> { | ||
resolve_numalgo2(did, public_key_encoding) | ||
} | ||
} | ||
|
||
impl ToNumalgo3 for Numalgo2 { | ||
fn to_numalgo3(did: &Did) -> Result<PeerDid<Numalgo3>, DidPeerError> { | ||
generate_numalgo3(did) | ||
} | ||
} |
Oops, something went wrong.