Skip to main content

Plaintext

Struct Plaintext 

Source
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

Source

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.

Source

pub fn string(s: impl Into<String>) -> Self

A type:str leaf.

Source

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.

Source

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.

Source

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.

Source

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:].

Source

pub fn leaf_type(&self) -> LeafType

The declared type.

Source

pub fn len(&self) -> usize

Length in bytes. Safe to log; it is what Debug prints.

Source

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).

Source

pub fn expose(&self) -> &[u8]

The plaintext bytes. Named to be searched for.

Source

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.

Source

pub fn validate(&self) -> Result<(), WireError>

Check the bytes really are a valid rendering of the declared type.

Not called on the hot decrypt path — sops does not validate either, and a file it accepts must not be one we reject. Offered for filestatus-style inspection and for tests.

Trait Implementations§

Source§

impl Clone for Plaintext

Source§

fn clone(&self) -> Plaintext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Plaintext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Plaintext

Source§

impl PartialEq for Plaintext

Source§

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.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.