Struct sshkeys::Writer

source ·
pub struct Writer { /* private fields */ }
Expand description

A Writer is used for encoding a key in OpenSSH compatible format.

Implementations§

source§

impl Writer

source

pub fn new() -> Writer

Creates a new Writer instance.

§Example
let writer = sshkeys::Writer::new();
source

pub fn write_bytes(&mut self, val: &[u8])

Writes a byte sequence to the underlying vector. The value is represented as a the byte sequence length, followed by the actual byte sequence.

§Example
let mut writer = sshkeys::Writer::new();
writer.write_bytes(&[0, 0, 0, 42]);
let bytes = writer.into_bytes();
assert_eq!(bytes, vec![0, 0, 0, 4, 0, 0, 0, 42]);
source

pub fn write_string(&mut self, val: &str)

Writes a string value to the underlying byte sequence.

§Example
let mut writer = sshkeys::Writer::new();
writer.write_string("a test string");
let bytes = writer.into_bytes();
assert_eq!(bytes, [0, 0, 0, 13, 97, 32, 116, 101, 115, 116, 32, 115, 116, 114, 105, 110, 103]);
source

pub fn write_mpint(&mut self, val: &[u8])

Writes an mpint value to the underlying byte sequence. If the MSB bit of the first byte is set then the number is negative, otherwise it is positive. Positive numbers must be preceeded by a leading zero byte according to RFC 4251, section 5.

§Example
let mut writer = sshkeys::Writer::new();
writer.write_mpint(&[1, 0, 1]);
let bytes = writer.into_bytes();
assert_eq!(bytes, [0, 0, 0, 3, 1, 0, 1]);
source

pub fn into_bytes(self) -> Vec<u8>

Converts the Writer into a byte sequence. This consumes the underlying byte sequence used by the Writer.

§Example
let mut writer = sshkeys::Writer::new();
writer.write_string("some data");
let bytes = writer.into_bytes();
assert_eq!(bytes, [0, 0, 0, 9, 115, 111, 109, 101, 32, 100, 97, 116, 97]);

Trait Implementations§

source§

impl Debug for Writer

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Writer

§

impl RefUnwindSafe for Writer

§

impl Send for Writer

§

impl Sync for Writer

§

impl Unpin for Writer

§

impl UnwindSafe for Writer

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.