openpgp: Provide bundle conversion functions in marker traits.

parent e98e4dc7
......@@ -85,6 +85,18 @@ pub trait KeyParts: fmt::Debug {
fn convert_key_ref<R: KeyRole>(key: &Key<UnspecifiedParts, R>)
-> Result<&Key<Self, R>>
where Self: Sized;
/// Converts a key bundle with unspecified parts into this kind of
/// key bundle.
fn convert_bundle<R: KeyRole>(bundle: KeyBundle<UnspecifiedParts, R>)
-> Result<KeyBundle<Self, R>>
where Self: Sized;
/// Converts a reference to a key bundle with unspecified parts
/// into this kind of key bundle reference.
fn convert_bundle_ref<R: KeyRole>(bundle: &KeyBundle<UnspecifiedParts, R>)
-> Result<&KeyBundle<Self, R>>
where Self: Sized;
}
/// A marker trait that indicates whether a `Key` is a primary key or
......@@ -100,6 +112,18 @@ pub trait KeyRole: fmt::Debug {
fn convert_key_ref<P: KeyParts>(key: &Key<P, UnspecifiedRole>)
-> &Key<P, Self>
where Self: Sized;
/// Converts a key bundle with unspecified role into this kind of
/// key bundle.
fn convert_bundle<P: KeyParts>(bundle: KeyBundle<P, UnspecifiedRole>)
-> KeyBundle<P, Self>
where Self: Sized;
/// Converts a reference to a key bundle with unspecified role
/// into this kind of key bundle reference.
fn convert_bundle_ref<P: KeyParts>(bundle: &KeyBundle<P, UnspecifiedRole>)
-> &KeyBundle<P, Self>
where Self: Sized;
}
/// Indicates that a `Key` should be treated like a public key.
......@@ -120,6 +144,16 @@ impl KeyParts for PublicParts {
-> Result<&Key<Self, R>> {
Ok(key.into())
}
fn convert_bundle<R: KeyRole>(bundle: KeyBundle<UnspecifiedParts, R>)
-> Result<KeyBundle<Self, R>> {
Ok(bundle.into())
}
fn convert_bundle_ref<R: KeyRole>(bundle: &KeyBundle<UnspecifiedParts, R>)
-> Result<&KeyBundle<Self, R>> {
Ok(bundle.into())
}
}
/// Indicates that a `Key` should be treated like a secret key.
......@@ -140,6 +174,16 @@ impl KeyParts for SecretParts {
-> Result<&Key<Self, R>> {
key.try_into()
}
fn convert_bundle<R: KeyRole>(bundle: KeyBundle<UnspecifiedParts, R>)
-> Result<KeyBundle<Self, R>> {
bundle.try_into()
}
fn convert_bundle_ref<R: KeyRole>(bundle: &KeyBundle<UnspecifiedParts, R>)
-> Result<&KeyBundle<Self, R>> {
bundle.try_into()
}
}
/// Indicates that a `Key`'s parts are unspecified.
......@@ -163,6 +207,16 @@ impl KeyParts for UnspecifiedParts {
-> Result<&Key<Self, R>> {
Ok(key)
}
fn convert_bundle<R: KeyRole>(bundle: KeyBundle<UnspecifiedParts, R>)
-> Result<KeyBundle<Self, R>> {
Ok(bundle)
}
fn convert_bundle_ref<R: KeyRole>(bundle: &KeyBundle<UnspecifiedParts, R>)
-> Result<&KeyBundle<Self, R>> {
Ok(bundle)
}
}
/// Indicates that a `Key` should treated like a primary key.
......@@ -178,6 +232,16 @@ impl KeyRole for PrimaryRole {
-> &Key<P, Self> {
key.into()
}
fn convert_bundle<P: KeyParts>(bundle: KeyBundle<P, UnspecifiedRole>)
-> KeyBundle<P, Self> {
bundle.into()
}
fn convert_bundle_ref<P: KeyParts>(bundle: &KeyBundle<P, UnspecifiedRole>)
-> &KeyBundle<P, Self> {
bundle.into()
}
}
/// Indicates that a `Key` should treated like a subkey key.
......@@ -193,6 +257,16 @@ impl KeyRole for SubordinateRole {
-> &Key<P, Self> {
key.into()
}
fn convert_bundle<P: KeyParts>(bundle: KeyBundle<P, UnspecifiedRole>)
-> KeyBundle<P, Self> {
bundle.into()
}
fn convert_bundle_ref<P: KeyParts>(bundle: &KeyBundle<P, UnspecifiedRole>)
-> &KeyBundle<P, Self> {
bundle.into()
}
}
/// Indicates that a `Key`'s role is unknown.
......@@ -211,6 +285,16 @@ impl KeyRole for UnspecifiedRole {
-> &Key<P, Self> {
key
}
fn convert_bundle<P: KeyParts>(bundle: KeyBundle<P, UnspecifiedRole>)
-> KeyBundle<P, Self> {
bundle
}
fn convert_bundle_ref<P: KeyParts>(bundle: &KeyBundle<P, UnspecifiedRole>)
-> &KeyBundle<P, Self> {
bundle
}
}
/// A Public Key.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment