Skip to content

Commit 83030e7

Browse files
committed
Add support for Opaque Objects
Signed-off-by: Nathaniel Clark <nclark@whamcloud.com>
1 parent 48ba509 commit 83030e7

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

src/types/request.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,7 @@ pub enum ManagedObject {
763763
// SecretData(SecretData),
764764
// Not implemented
765765

766-
// OpaqueObject(OpaqueObject),
767-
// Not implemented
766+
OpaqueObject(OpaqueObject),
768767
}
769768

770769
impl ManagedObject {
@@ -774,11 +773,11 @@ impl ManagedObject {
774773
ObjectType::PublicKey => PublicKey::fast_scan(scanner).map(Self::PublicKey),
775774
ObjectType::PrivateKey => PrivateKey::fast_scan(scanner).map(Self::PrivateKey),
776775
ObjectType::Template => Template::fast_scan(scanner).map(Self::Template),
776+
ObjectType::OpaqueObject => OpaqueObject::fast_scan(scanner).map(Self::OpaqueObject),
777777

778778
ObjectType::Certificate
779779
| ObjectType::SplitKey
780780
| ObjectType::SecretData
781-
| ObjectType::OpaqueObject
782781
| ObjectType::PGPKey => unimplemented!(),
783782
}
784783
}
@@ -789,11 +788,11 @@ impl ManagedObject {
789788
ObjectType::PublicKey => PublicKey::fast_scan_opt(scanner).map(|s| s.map(Self::PublicKey)),
790789
ObjectType::PrivateKey => PrivateKey::fast_scan_opt(scanner).map(|s| s.map(Self::PrivateKey)),
791790
ObjectType::Template => Template::fast_scan_opt(scanner).map(|s| s.map(Self::Template)),
791+
ObjectType::OpaqueObject => OpaqueObject::fast_scan_opt(scanner).map(|s| s.map(Self::OpaqueObject)),
792792

793793
ObjectType::Certificate
794794
| ObjectType::SplitKey
795795
| ObjectType::SecretData
796-
| ObjectType::OpaqueObject
797796
| ObjectType::PGPKey => unimplemented!(),
798797
}
799798
}
@@ -804,6 +803,7 @@ impl ManagedObject {
804803
ManagedObject::PublicKey(this) => this.format(formatter),
805804
ManagedObject::PrivateKey(this) => this.format(formatter),
806805
ManagedObject::Template(this) => this.format(formatter),
806+
ManagedObject::OpaqueObject(this) => this.format(formatter),
807807
}
808808
}
809809
}
@@ -836,6 +836,31 @@ pub struct Template(pub Vec<Attribute>);
836836

837837
impl_ttlv_serde!(struct Template(#[vec] attrs: Attribute) as 0x420090);
838838

839+
/// See KMIP 1.0 section 2.2.8 [Opaque Object](https://docs.oasis-open.org/kmip/spec/v1.0/os/kmip-spec-1.0-os.html#_Toc262581171)
840+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
841+
#[serde(rename = "0x42005B")]
842+
pub struct OpaqueObject(pub OpaqueDataType, pub OpaqueDataValue);
843+
844+
impl_ttlv_serde!(struct OpaqueObject(r#type: OpaqueDataType, value: OpaqueDataValue) as 0x42005B);
845+
846+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Display, PartialEq, Eq, Ordinalize)]
847+
#[serde(rename = "0x420059")]
848+
#[non_exhaustive]
849+
#[repr(u32)]
850+
pub enum OpaqueDataType {
851+
// This doesn't actually have any values
852+
#[serde(rename = "0x80000000")]
853+
Extension,
854+
}
855+
856+
impl_ttlv_serde!(enum OpaqueDataType as 0x420059);
857+
858+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
859+
#[serde(rename = "Transparent:0x42005A")]
860+
pub struct OpaqueDataValue(#[serde(with = "serde_bytes")] pub Vec<u8>);
861+
862+
impl_ttlv_serde!(bytes OpaqueDataValue as 0x42005A);
863+
839864
/// See KMIP 1.0 section 3.2 [Name](https://docs.oasis-open.org/kmip/spec/v1.0/os/kmip-spec-1.0-os.html#_Toc262581174).
840865
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
841866
#[serde(rename = "0x420053(0x420055,0x420054)")]

0 commit comments

Comments
 (0)