summaryrefslogtreecommitdiffstats
path: root/openpgp/src/subpacket.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-07-09 15:24:56 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-07-09 15:24:56 +0200
commitaef143f89e74f6b44f16561da2b6093f4166730b (patch)
treecfb2d446b355da5e843c8fd1f7cd4ca6b6fa09b4 /openpgp/src/subpacket.rs
parent627620533867cc136ebf4dfe4de8d087ffec803a (diff)
openpgp: Add and use a type specifying reasons for revocations.
Diffstat (limited to 'openpgp/src/subpacket.rs')
-rw-r--r--openpgp/src/subpacket.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/openpgp/src/subpacket.rs b/openpgp/src/subpacket.rs
index 677eca49..c79d3965 100644
--- a/openpgp/src/subpacket.rs
+++ b/openpgp/src/subpacket.rs
@@ -77,6 +77,7 @@ use constants::{
CompressionAlgorithm,
HashAlgorithm,
PublicKeyAlgorithm,
+ ReasonForRevocation,
SymmetricAlgorithm,
};
use conversions::{
@@ -616,7 +617,7 @@ pub enum SubpacketValue<'a> {
/// 1 octet of revocation code, N octets of reason string
ReasonForRevocation {
/// Machine-readable reason for revocation.
- code: u8,
+ code: ReasonForRevocation,
/// Human-readable reason for revocation.
reason: &'a [u8],
@@ -937,7 +938,7 @@ impl<'a> From<SubpacketRaw<'a>> for Subpacket<'a> {
// 1 octet of revocation code, N octets of reason string
if raw.value.len() >= 1 {
Some(SubpacketValue::ReasonForRevocation {
- code: raw.value[0],
+ code: raw.value[0].into(),
reason: &raw.value[1..],
})
} else {
@@ -2190,7 +2191,8 @@ impl Signature {
///
/// Note: if the signature contains multiple instances of this
/// subpacket, only the last one is considered.
- pub fn reason_for_revocation(&self) -> Option<(u8, &[u8])> {
+ pub fn reason_for_revocation(&self)
+ -> Option<(ReasonForRevocation, &[u8])> {
// 1 octet of revocation code, N octets of reason string
if let Some(sb) = self.subpacket(SubpacketTag::ReasonForRevocation) {
if let SubpacketValue::ReasonForRevocation {
@@ -2206,7 +2208,8 @@ impl Signature {
}
/// Sets the value of the Reason for Revocation subpacket.
- pub fn set_reason_for_revocation(&mut self, code: u8, reason: &[u8])
+ pub fn set_reason_for_revocation(&mut self, code: ReasonForRevocation,
+ reason: &[u8])
-> Result<()> {
self.hashed_area.replace(Subpacket::new(
SubpacketValue::ReasonForRevocation {
@@ -2505,8 +2508,10 @@ fn accessors() {
sig.set_signers_user_id(b"foobar").unwrap();
assert_eq!(sig.signers_user_id(), Some(&b"foobar"[..]));
- sig.set_reason_for_revocation(3, b"foobar").unwrap();
- assert_eq!(sig.reason_for_revocation(), Some((3, &b"foobar"[..])));
+ sig.set_reason_for_revocation(ReasonForRevocation::KeyRetired,
+ b"foobar").unwrap();
+ assert_eq!(sig.reason_for_revocation(),
+ Some((ReasonForRevocation::KeyRetired, &b"foobar"[..])));
let feats = Features::default().set_mdc(true);
sig.set_features(&feats).unwrap();
@@ -2916,13 +2921,14 @@ fn subpacket_test_2() {
}));
assert_eq!(sig.reason_for_revocation(),
- Some((0, &b"Forgot to set a sig expiration."[..])));
+ Some((ReasonForRevocation::Unspecified,
+ &b"Forgot to set a sig expiration."[..])));
assert_eq!(sig.subpacket(SubpacketTag::ReasonForRevocation),
Some(Subpacket {
critical: false,
tag: SubpacketTag::ReasonForRevocation,
value: SubpacketValue::ReasonForRevocation {
- code: 0,
+ code: ReasonForRevocation::Unspecified,
reason: &b"Forgot to set a sig expiration."[..],
},
}));