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

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

Implementations

Creates a new Writer instance.

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

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]);

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]);

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]);

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.