pub struct Plaintext { /* private fields */ }Expand description
A leaf’s plaintext bytes, together with the type they render as.
No Display, no Deref<Target = str>, no AsRef<str>, no Into<String>,
and a Debug that prints a length rather than content. Reading the bytes
takes Plaintext::expose — deliberately one greppable token, so a review
searches for a presence instead of noticing an absence. Same discipline as
cofre_secret::Secret, applied to a value that arrives from a file rather
than from an operator.
Implementations§
Source§impl Plaintext
impl Plaintext
Sourcepub fn from_wire(bytes: Vec<u8>, ty: LeafType) -> Self
pub fn from_wire(bytes: Vec<u8>, ty: LeafType) -> Self
Wrap bytes that are already the canonical rendering for ty.
Used on the decrypt path, where the bytes came out of GCM and the type came off the wire.
Sourcepub fn integer(v: i64) -> Self
pub fn integer(v: i64) -> Self
A type:int leaf. Rendered by Go’s strconv.Itoa, which for the 64-bit
int in play is just decimal — matching Rust’s i64 Display.
Sourcepub fn float(v: f64) -> Self
pub fn float(v: f64) -> Self
A type:float leaf.
Go uses strconv.FormatFloat(v, 'f', -1, 64): shortest representation
that round-trips, never exponent notation, and — the comment in
cipher.go says so outright — no zero padding after the point, because
the Python implementation didn’t pad. Rust’s {} for f64 is also
shortest-round-trip, but it will reach for exponent form on extreme
magnitudes, so those are rendered positionally by hand.
Sourcepub fn boolean(v: bool) -> Self
pub fn boolean(v: bool) -> Self
A type:bool leaf. True/False — Python titlecase, as cipher.go
notes explicitly. Writing Rust’s true/false here changes the MAC.
Sourcepub fn comment(body: impl Into<String>) -> Self
pub fn comment(body: impl Into<String>) -> Self
A type:comment leaf. The stored body excludes the leading #, which the
YAML store strips with commentLine[1:].
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the value is empty — which the format treats as a fixed point in
both directions (see EncryptedLeaf::render).
Sourcepub fn mac_bytes(&self) -> &[u8] ⓘ
pub fn mac_bytes(&self) -> &[u8] ⓘ
The bytes this leaf contributes to the MAC.
sops.ToBytes over the plaintext, which for every type we can emit is
the same canonical rendering already held here — so this is the identity.
It exists as a named method anyway, because the MAC contribution and the
stored bytes are conceptually two different questions and a future type
could separate them.
Trait Implementations§
impl Eq for Plaintext
Source§impl PartialEq for Plaintext
impl PartialEq for Plaintext
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Constant-time in the bytes.
A plaintext comparison is a secret comparison — the obvious place it happens is “did this value change?” during an edit, where a timing signal leaks a prefix length. Length and type are not secret (the length ships in the ciphertext), so short-circuiting on those leaks nothing and keeps the byte compare well-defined.