-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Miroslav Kovar <[email protected]>
- Loading branch information
Showing
19 changed files
with
346 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,6 @@ on: | |
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- "**" | ||
|
||
env: | ||
DOCKER_BUILDKIT: 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
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
mod numalgo; | ||
mod numalgos; | ||
mod peer_did; | ||
mod regex; | ||
mod transform; | ||
pub(super) mod traits; | ||
|
||
pub use numalgo::Numalgo; | ||
pub use peer_did::PeerDid; | ||
pub use numalgos::{numalgo0, numalgo1, numalgo2, numalgo3, NumalgoKind}; | ||
pub use peer_did::{GenericPeerDid, PeerDid}; |
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,43 @@ | ||
pub mod numalgo0; | ||
pub mod numalgo1; | ||
pub mod numalgo2; | ||
pub mod numalgo3; | ||
|
||
use std::fmt::Display; | ||
|
||
use crate::error::DidPeerError; | ||
|
||
use super::{numalgo0::Numalgo0, numalgo1::Numalgo1, numalgo2::Numalgo2, numalgo3::Numalgo3, 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,12 @@ | ||
use crate::peer_did::traits::Numalgo; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct Numalgo0; | ||
|
||
impl Numalgo for Numalgo0 { | ||
const NUMALGO_CHAR: char = '0'; | ||
|
||
fn default() -> Self { | ||
Self | ||
} | ||
} |
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,12 @@ | ||
use crate::peer_did::traits::Numalgo; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct Numalgo1; | ||
|
||
impl Numalgo for Numalgo1 { | ||
const NUMALGO_CHAR: char = '1'; | ||
|
||
fn default() -> Self { | ||
Self | ||
} | ||
} |
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,36 @@ | ||
use did_doc::schema::did_doc::DidDocument; | ||
use did_doc_sov::extra_fields::ExtraFieldsSov; | ||
use did_parser::Did; | ||
|
||
use crate::{ | ||
error::DidPeerError, | ||
peer_did::{ | ||
traits::{Numalgo, ResolvablePeerDid, ToNumalgo3}, | ||
PeerDid, | ||
}, | ||
}; | ||
|
||
use super::numalgo3::Numalgo3; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct Numalgo2; | ||
|
||
impl Numalgo for Numalgo2 { | ||
const NUMALGO_CHAR: char = '2'; | ||
|
||
fn default() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
impl ResolvablePeerDid for Numalgo2 { | ||
fn resolve(&self) -> Result<DidDocument<ExtraFieldsSov>, DidPeerError> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl ToNumalgo3 for Numalgo2 { | ||
fn to_numalgo3(&self, did: &Did) -> Result<PeerDid<Numalgo3>, DidPeerError> { | ||
todo!() | ||
} | ||
} |
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,26 @@ | ||
use did_parser::Did; | ||
|
||
use crate::{ | ||
error::DidPeerError, | ||
peer_did::{ | ||
traits::{Numalgo, ToNumalgo3}, | ||
PeerDid, | ||
}, | ||
}; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct Numalgo3; | ||
|
||
impl Numalgo for Numalgo3 { | ||
const NUMALGO_CHAR: char = '3'; | ||
|
||
fn default() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
impl ToNumalgo3 for Numalgo3 { | ||
fn to_numalgo3(&self, did: &Did) -> Result<PeerDid<Numalgo3>, DidPeerError> { | ||
todo!() | ||
} | ||
} |
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,63 @@ | ||
use crate::{ | ||
error::DidPeerError, | ||
peer_did::{numalgo2::Numalgo2, numalgo3::Numalgo3, NumalgoKind}, | ||
}; | ||
use did_parser::Did; | ||
use serde::{Deserialize, Deserializer}; | ||
|
||
use super::{ | ||
parsing::{parse_numalgo, parse_transform, validate}, | ||
PeerDid, | ||
}; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum GenericPeerDid { | ||
Numalgo2(PeerDid<Numalgo2>), | ||
Numalgo3(PeerDid<Numalgo3>), | ||
} | ||
|
||
impl GenericPeerDid { | ||
pub fn parse<T>(did: T) -> Result<GenericPeerDid, DidPeerError> | ||
where | ||
Did: TryFrom<T>, | ||
<Did as TryFrom<T>>::Error: Into<DidPeerError>, | ||
{ | ||
let did: Did = did.try_into().map_err(Into::into)?; | ||
let numalgo = parse_numalgo(&did)?; | ||
let transform = match numalgo { | ||
NumalgoKind::InceptionKeyWithoutDoc(_) | NumalgoKind::GenesisDoc(_) => Some(parse_transform(&did)?), | ||
_ => None, | ||
}; | ||
validate(&did)?; | ||
let parsed = match numalgo { | ||
NumalgoKind::MultipleInceptionKeys(numalgo) => GenericPeerDid::Numalgo2(PeerDid { | ||
did, | ||
numalgo, | ||
transform, | ||
}), | ||
_ => GenericPeerDid::Numalgo3(PeerDid { | ||
did, | ||
numalgo: Numalgo3, | ||
transform, | ||
}), | ||
}; | ||
Ok(parsed) | ||
} | ||
|
||
pub fn numalgo(&self) -> NumalgoKind { | ||
match self { | ||
GenericPeerDid::Numalgo2(peer_did) => NumalgoKind::MultipleInceptionKeys(peer_did.numalgo), | ||
GenericPeerDid::Numalgo3(peer_did) => NumalgoKind::DidShortening(peer_did.numalgo), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for GenericPeerDid { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let did = String::deserialize(deserializer)?; | ||
Self::parse(did).map_err(serde::de::Error::custom) | ||
} | ||
} |
Oops, something went wrong.