summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-07-03 11:44:00 +0200
committerJustus Winter <justus@sequoia-pgp.org>2023-07-18 16:41:15 +0200
commit430dcbf562d97b58dfa564d7037c9218df253626 (patch)
treec8a1bd1753b1f32811d422529ad86419a6d4d7db
parent122cdd7c624314651a6c953530bd5204e1996ef0 (diff)
openpgp: Rename accessors for the raw bytes.
-rw-r--r--openpgp/src/packet/signature/subpacket.rs10
-rw-r--r--openpgp/src/serialize.rs12
-rw-r--r--openpgp/src/types/bitfield.rs4
-rw-r--r--openpgp/src/types/features.rs6
-rw-r--r--openpgp/src/types/key_flags.rs16
-rw-r--r--openpgp/src/types/server_preferences.rs6
6 files changed, 27 insertions, 27 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 0eb5f8ff..18d64b1f 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -1336,7 +1336,7 @@ impl NotationDataFlags {
/// Returns a slice containing the raw values.
pub(crate) fn as_slice(&self) -> &[u8] {
- self.0.as_slice()
+ self.0.as_bytes()
}
/// Returns whether the specified notation data flag is set.
@@ -1383,10 +1383,10 @@ impl NotationDataFlags {
/// # Ok(()) }
/// ```
pub fn set(mut self, bit: usize) -> Result<Self> {
- assert_eq!(self.0.as_slice().len(), 4);
+ assert_eq!(self.0.as_bytes().len(), 4);
let byte = bit / 8;
if byte < 4 {
- self.0.as_slice_mut()[byte] |= 1 << (bit % 8);
+ self.0.as_bytes_mut()[byte] |= 1 << (bit % 8);
Ok(self)
} else {
Err(Error::InvalidArgument(
@@ -1413,10 +1413,10 @@ impl NotationDataFlags {
/// # Ok(()) }
/// ```
pub fn clear(mut self, bit: usize) -> Result<Self> {
- assert_eq!(self.0.as_slice().len(), 4);
+ assert_eq!(self.0.as_bytes().len(), 4);
let byte = bit / 8;
if byte < 4 {
- self.0.as_slice_mut()[byte] &= !(1 << (bit % 8));
+ self.0.as_bytes_mut()[byte] &= !(1 << (bit % 8));
Ok(self)
} else {
Err(Error::InvalidArgument(
diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs
index b30f0de0..e4327b73 100644
--- a/openpgp/src/serialize.rs
+++ b/openpgp/src/serialize.rs
@@ -1466,7 +1466,7 @@ impl Marshal for SubpacketValue {
o.write_all(&[(*a).into()])?;
},
KeyServerPreferences(ref p) =>
- o.write_all(p.as_slice())?,
+ o.write_all(p.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_slice())?,
+ o.write_all(f.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_slice())?,
+ o.write_all(f.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_slice().len(),
+ KeyServerPreferences(ref p) => p.as_bytes().len(),
PreferredKeyServer(ref p) => p.len(),
PrimaryUserID(_) => 1,
PolicyURI(ref p) => p.len(),
- KeyFlags(ref f) => f.as_slice().len(),
+ KeyFlags(ref f) => f.as_bytes().len(),
SignersUserID(ref uid) => uid.len(),
ReasonForRevocation { ref reason, .. } => 1 + reason.len(),
- Features(ref f) => f.as_slice().len(),
+ Features(ref f) => f.as_bytes().len(),
SignatureTarget { ref digest, .. } => 2 + digest.len(),
EmbeddedSignature(sig) => sig.serialized_len(),
IssuerFingerprint(ref fp) =>
diff --git a/openpgp/src/types/bitfield.rs b/openpgp/src/types/bitfield.rs
index dea6439a..6df0791a 100644
--- a/openpgp/src/types/bitfield.rs
+++ b/openpgp/src/types/bitfield.rs
@@ -59,12 +59,12 @@ impl Bitfield {
}
/// Returns a slice containing the raw values.
- pub(crate) fn as_slice(&self) -> &[u8] {
+ pub fn as_bytes(&self) -> &[u8] {
&self.raw
}
/// Returns a slice containing the raw values.
- pub(crate) fn as_slice_mut(&mut self) -> &mut [u8] {
+ pub fn as_bytes_mut(&mut self) -> &mut [u8] {
&mut self.raw
}
diff --git a/openpgp/src/types/features.rs b/openpgp/src/types/features.rs
index c77d9f85..b085a000 100644
--- a/openpgp/src/types/features.rs
+++ b/openpgp/src/types/features.rs
@@ -145,8 +145,8 @@ impl Features {
}
/// Returns a slice containing the raw values.
- pub(crate) fn as_slice(&self) -> &[u8] {
- self.0.as_slice()
+ pub(crate) fn as_bytes(&self) -> &[u8] {
+ self.0.as_bytes()
}
/// Returns whether the specified feature flag is set.
@@ -369,7 +369,7 @@ mod tests {
quickcheck! {
fn roundtrip(val: Features) -> bool {
- let mut q_bytes = val.as_slice().to_vec();
+ let mut q_bytes = val.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 c2f3e62a..a71cff03 100644
--- a/openpgp/src/types/key_flags.rs
+++ b/openpgp/src/types/key_flags.rs
@@ -109,8 +109,8 @@ impl BitAnd for &KeyFlags {
type Output = KeyFlags;
fn bitand(self, rhs: Self) -> KeyFlags {
- let l = self.as_slice();
- let r = rhs.as_slice();
+ let l = self.as_bytes();
+ let r = rhs.as_bytes();
let mut c = Vec::with_capacity(std::cmp::min(l.len(), r.len()));
for (l, r) in l.iter().zip(r.iter()) {
@@ -125,8 +125,8 @@ impl BitOr for &KeyFlags {
type Output = KeyFlags;
fn bitor(self, rhs: Self) -> KeyFlags {
- let l = self.as_slice();
- let r = rhs.as_slice();
+ let l = self.as_bytes();
+ let r = rhs.as_bytes();
// Make l the longer one.
let (l, r) = if l.len() > r.len() {
@@ -162,8 +162,8 @@ impl KeyFlags {
}
/// Returns a slice containing the raw values.
- pub(crate) fn as_slice(&self) -> &[u8] {
- self.0.as_slice()
+ pub(crate) fn as_bytes(&self) -> &[u8] {
+ self.0.as_bytes()
}
/// Compares two key flag sets for semantic equality.
@@ -443,7 +443,7 @@ impl KeyFlags {
/// Returns whether no flags are set.
pub fn is_empty(&self) -> bool {
- self.as_slice().iter().all(|b| *b == 0)
+ self.as_bytes().iter().all(|b| *b == 0)
}
}
@@ -483,7 +483,7 @@ mod tests {
quickcheck! {
fn roundtrip(val: KeyFlags) -> bool {
- let mut q_bytes = val.as_slice().to_vec();
+ let mut q_bytes = val.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 faa1ae4a..4708fd3c 100644
--- a/openpgp/src/types/server_preferences.rs
+++ b/openpgp/src/types/server_preferences.rs
@@ -100,8 +100,8 @@ impl KeyServerPreferences {
}
/// Returns a slice containing the raw values.
- pub(crate) fn as_slice(&self) -> &[u8] {
- self.0.as_slice()
+ pub(crate) fn as_bytes(&self) -> &[u8] {
+ self.0.as_bytes()
}
/// Compares two key server preference sets for semantic equality.
@@ -298,7 +298,7 @@ mod tests {
quickcheck! {
fn roundtrip(val: KeyServerPreferences) -> bool {
- let mut q_bytes = val.as_slice().to_vec();
+ let mut q_bytes = val.as_bytes().to_vec();
let q = KeyServerPreferences::new(&q_bytes);
assert_eq!(val, q);
assert!(val.normalized_eq(&q));