diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-07-03 13:50:00 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-07-18 17:06:52 +0200 |
commit | da25fd9a17f90813f8d7a85d63fe88fa2b2e1ca5 (patch) | |
tree | 1c3be7d5f83a8a9e36aca0cb80a06e0f2daf6f4b | |
parent | 40b77ed618fa93432b3bb4e3ba8a43c5f2e2cb2a (diff) |
openpgp: Use public functions, remove pub(crate) accessors.
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 5 | ||||
-rw-r--r-- | openpgp/src/serialize.rs | 14 | ||||
-rw-r--r-- | openpgp/src/types/features.rs | 7 | ||||
-rw-r--r-- | openpgp/src/types/key_flags.rs | 17 | ||||
-rw-r--r-- | openpgp/src/types/server_preferences.rs | 7 |
5 files changed, 15 insertions, 35 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 45e1d5ab..cbba8454 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -1340,11 +1340,6 @@ impl NotationDataFlags { &self.0 } - /// Returns a slice containing the raw values. - pub(crate) fn as_slice(&self) -> &[u8] { - self.0.as_bytes() - } - /// Returns whether the specified notation data flag is set. /// /// # Examples diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index e4327b73..6dcc1845 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -1451,7 +1451,7 @@ impl Marshal for SubpacketValue { Issuer(ref id) => o.write_all(id.as_bytes())?, NotationData(nd) => { - o.write_all(nd.flags().as_slice())?; + o.write_all(nd.flags().as_bitfield().as_bytes())?; write_be_u16(o, nd.name().len() as u16)?; write_be_u16(o, nd.value().len() as u16)?; o.write_all(nd.name().as_bytes())?; @@ -1466,7 +1466,7 @@ impl Marshal for SubpacketValue { o.write_all(&[(*a).into()])?; }, KeyServerPreferences(ref p) => - o.write_all(p.as_bytes())?, + o.write_all(p.as_bitfield().as_bytes())?, PreferredKeyServer(ref p) => o.write_all(p)?, PrimaryUserID(p) => @@ -1474,7 +1474,7 @@ impl Marshal for SubpacketValue { PolicyURI(ref p) => o.write_all(p)?, KeyFlags(ref f) => - o.write_all(f.as_bytes())?, + o.write_all(f.as_bitfield().as_bytes())?, SignersUserID(ref uid) => o.write_all(uid)?, ReasonForRevocation { ref code, ref reason } => { @@ -1482,7 +1482,7 @@ impl Marshal for SubpacketValue { o.write_all(reason)?; }, Features(ref f) => - o.write_all(f.as_bytes())?, + o.write_all(f.as_bitfield().as_bytes())?, SignatureTarget { pk_algo, hash_algo, ref digest } => { o.write_all(&[(*pk_algo).into(), (*hash_algo).into()])?; o.write_all(digest)?; @@ -1546,14 +1546,14 @@ impl MarshalInto for SubpacketValue { NotationData(nd) => 4 + 2 + 2 + nd.name().len() + nd.value().len(), PreferredHashAlgorithms(ref p) => p.len(), PreferredCompressionAlgorithms(ref p) => p.len(), - KeyServerPreferences(ref p) => p.as_bytes().len(), + KeyServerPreferences(p) => p.as_bitfield().as_bytes().len(), PreferredKeyServer(ref p) => p.len(), PrimaryUserID(_) => 1, PolicyURI(ref p) => p.len(), - KeyFlags(ref f) => f.as_bytes().len(), + KeyFlags(f) => f.as_bitfield().as_bytes().len(), SignersUserID(ref uid) => uid.len(), ReasonForRevocation { ref reason, .. } => 1 + reason.len(), - Features(ref f) => f.as_bytes().len(), + Features(f) => f.as_bitfield().as_bytes().len(), SignatureTarget { ref digest, .. } => 2 + digest.len(), EmbeddedSignature(sig) => sig.serialized_len(), IssuerFingerprint(ref fp) => diff --git a/openpgp/src/types/features.rs b/openpgp/src/types/features.rs index 65144e25..28fcfba8 100644 --- a/openpgp/src/types/features.rs +++ b/openpgp/src/types/features.rs @@ -153,11 +153,6 @@ impl Features { self.0.normalized_eq(&other.0) } - /// Returns a slice containing the raw values. - pub(crate) fn as_bytes(&self) -> &[u8] { - self.0.as_bytes() - } - /// Returns whether the specified feature flag is set. /// /// # Examples @@ -382,7 +377,7 @@ mod tests { quickcheck! { fn roundtrip(val: Features) -> bool { - let mut q_bytes = val.as_bytes().to_vec(); + let mut q_bytes = val.as_bitfield().as_bytes().to_vec(); let q = Features::new(&q_bytes); assert_eq!(val, q); assert!(val.normalized_eq(&q)); diff --git a/openpgp/src/types/key_flags.rs b/openpgp/src/types/key_flags.rs index aa8f12f0..d6ed335a 100644 --- a/openpgp/src/types/key_flags.rs +++ b/openpgp/src/types/key_flags.rs @@ -108,8 +108,8 @@ impl BitAnd for &KeyFlags { type Output = KeyFlags; fn bitand(self, rhs: Self) -> KeyFlags { - let l = self.as_bytes(); - let r = rhs.as_bytes(); + let l = self.as_bitfield().as_bytes(); + let r = rhs.as_bitfield().as_bytes(); let mut c = Vec::with_capacity(std::cmp::min(l.len(), r.len())); for (l, r) in l.iter().zip(r.iter()) { @@ -124,8 +124,8 @@ impl BitOr for &KeyFlags { type Output = KeyFlags; fn bitor(self, rhs: Self) -> KeyFlags { - let l = self.as_bytes(); - let r = rhs.as_bytes(); + let l = self.as_bitfield().as_bytes(); + let r = rhs.as_bitfield().as_bytes(); // Make l the longer one. let (l, r) = if l.len() > r.len() { @@ -170,11 +170,6 @@ impl KeyFlags { &mut self.0 } - /// Returns a slice containing the raw values. - pub(crate) fn as_bytes(&self) -> &[u8] { - self.0.as_bytes() - } - /// Compares two key flag sets for semantic equality. /// /// `KeyFlags`' implementation of `PartialEq` compares two key @@ -456,7 +451,7 @@ impl KeyFlags { /// Returns whether no flags are set. pub fn is_empty(&self) -> bool { - self.as_bytes().iter().all(|b| *b == 0) + self.as_bitfield().as_bytes().iter().all(|b| *b == 0) } } @@ -496,7 +491,7 @@ mod tests { quickcheck! { fn roundtrip(val: KeyFlags) -> bool { - let mut q_bytes = val.as_bytes().to_vec(); + let mut q_bytes = val.as_bitfield().as_bytes().to_vec(); let q = KeyFlags::new(&q_bytes); assert_eq!(val, q); assert!(val.normalized_eq(&q)); diff --git a/openpgp/src/types/server_preferences.rs b/openpgp/src/types/server_preferences.rs index ef989bf6..f5e8a690 100644 --- a/openpgp/src/types/server_preferences.rs +++ b/openpgp/src/types/server_preferences.rs @@ -108,11 +108,6 @@ impl KeyServerPreferences { &mut self.0 } - /// Returns a slice containing the raw values. - pub(crate) fn as_bytes(&self) -> &[u8] { - self.0.as_bytes() - } - /// Compares two key server preference sets for semantic equality. /// /// `KeyServerPreferences`' implementation of `PartialEq` compares @@ -311,7 +306,7 @@ mod tests { quickcheck! { fn roundtrip(val: KeyServerPreferences) -> bool { - let mut q_bytes = val.as_bytes().to_vec(); + let mut q_bytes = val.as_bitfield().as_bytes().to_vec(); let q = KeyServerPreferences::new(&q_bytes); assert_eq!(val, q); assert!(val.normalized_eq(&q)); |