pub struct Base64UrlBytes(/* private fields */);Expand description
A wrapper around raw bytes that serializes to/from base64url encoding.
This type provides:
- Base64url encoding without padding (per RFC 7517)
- Constant-time base64 operations via
base64ct - Automatic memory zeroing on drop via
zeroize - Explicit constant-time byte comparison via
Base64UrlBytes::ct_eq
§Security Note
PartialEq for this type is a regular byte equality check and is not
guaranteed to be constant-time. For secret-dependent comparisons, use
Base64UrlBytes::ct_eq.
§Examples
use jwk_simple::encoding::Base64UrlBytes;
// Create from raw bytes
let bytes = Base64UrlBytes::new(vec![1, 2, 3, 4]);
// Serialize to JSON (base64url encoded)
let json = serde_json::to_string(&bytes).unwrap();
assert_eq!(json, "\"AQIDBA\"");
// Deserialize from JSON
let decoded: Base64UrlBytes = serde_json::from_str(&json).unwrap();
assert_eq!(decoded.as_bytes(), &[1, 2, 3, 4]);Implementations§
Source§impl Base64UrlBytes
impl Base64UrlBytes
Sourcepub fn new(bytes: Vec<u8>) -> Self
pub fn new(bytes: Vec<u8>) -> Self
Creates a new Base64UrlBytes from raw bytes.
§Examples
use jwk_simple::encoding::Base64UrlBytes;
let bytes = Base64UrlBytes::new(vec![0x01, 0x02, 0x03]);
assert_eq!(bytes.len(), 3);Sourcepub fn from_base64url(encoded: &str) -> Result<Self>
pub fn from_base64url(encoded: &str) -> Result<Self>
Sourcepub fn to_base64url(&self) -> String
pub fn to_base64url(&self) -> String
Encodes the bytes as a base64url string (without padding).
§Examples
use jwk_simple::encoding::Base64UrlBytes;
let bytes = Base64UrlBytes::new(vec![1, 2, 3, 4]);
assert_eq!(bytes.to_base64url(), "AQIDBA");Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns a reference to the underlying bytes.
§Examples
use jwk_simple::encoding::Base64UrlBytes;
let bytes = Base64UrlBytes::new(vec![1, 2, 3]);
assert_eq!(bytes.as_bytes(), &[1, 2, 3]);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the underlying bytes.
§Examples
use jwk_simple::encoding::Base64UrlBytes;
let bytes = Base64UrlBytes::new(vec![1, 2, 3]);
assert_eq!(bytes.len(), 3);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the underlying bytes are empty.
§Examples
use jwk_simple::encoding::Base64UrlBytes;
let empty = Base64UrlBytes::new(vec![]);
assert!(empty.is_empty());
let not_empty = Base64UrlBytes::new(vec![1]);
assert!(!not_empty.is_empty());Sourcepub fn into_bytes(self) -> Zeroizing<Vec<u8>>
pub fn into_bytes(self) -> Zeroizing<Vec<u8>>
Consumes the wrapper and returns the underlying bytes.
The returned bytes are wrapped in Zeroizing to ensure they are
zeroized on drop, preserving the security guarantees of this type.
§Examples
use jwk_simple::encoding::Base64UrlBytes;
let bytes = Base64UrlBytes::new(vec![1, 2, 3]);
let raw = bytes.into_bytes();
assert_eq!(&*raw, &vec![1, 2, 3]);Trait Implementations§
Source§impl AsRef<[u8]> for Base64UrlBytes
impl AsRef<[u8]> for Base64UrlBytes
Source§impl Clone for Base64UrlBytes
impl Clone for Base64UrlBytes
Source§fn clone(&self) -> Base64UrlBytes
fn clone(&self) -> Base64UrlBytes
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ConstantTimeEq for Base64UrlBytes
impl ConstantTimeEq for Base64UrlBytes
Source§impl Debug for Base64UrlBytes
impl Debug for Base64UrlBytes
Source§impl<'de> Deserialize<'de> for Base64UrlBytes
impl<'de> Deserialize<'de> for Base64UrlBytes
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Drop for Base64UrlBytes
impl Drop for Base64UrlBytes
Source§impl From<&[u8]> for Base64UrlBytes
impl From<&[u8]> for Base64UrlBytes
Source§impl Hash for Base64UrlBytes
impl Hash for Base64UrlBytes
Source§impl PartialEq for Base64UrlBytes
impl PartialEq for Base64UrlBytes
Source§impl Serialize for Base64UrlBytes
impl Serialize for Base64UrlBytes
Source§impl Zeroize for Base64UrlBytes
impl Zeroize for Base64UrlBytes
impl Eq for Base64UrlBytes
impl StructuralPartialEq for Base64UrlBytes
Auto Trait Implementations§
impl Freeze for Base64UrlBytes
impl RefUnwindSafe for Base64UrlBytes
impl Send for Base64UrlBytes
impl Sync for Base64UrlBytes
impl Unpin for Base64UrlBytes
impl UnsafeUnpin for Base64UrlBytes
impl UnwindSafe for Base64UrlBytes
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.