Signer

Struct Signer 

Source
pub struct Signer { /* private fields */ }
Expand description

Builder for signing operations.

§Examples

Basic signing:

use libsignify_rs::{KeyGenerator, Signer};
use tempfile::tempdir;
use std::fs;

let dir = tempdir()?;
let pub_path = dir.path().join("key.pub");
let sec_path = dir.path().join("key.sec");
let msg_path = dir.path().join("msg.txt");
let sig_path = dir.path().join("msg.sig");

// Setup: Generate keys and message
KeyGenerator::new().rounds(0).generate(&pub_path, &sec_path)?;
fs::write(&msg_path, "test message")?;

// Sign
Signer::new()
    .seckey(&sec_path)
    .sign(&msg_path, &sig_path)?;

assert!(sig_path.exists());

Embedded signature:

Signer::new()
    .seckey(&sec_path)
    .embed(true)
    .sign(&msg_path, &sig_path)?;

Gzip signing:

use flate2::write::GzEncoder;
use flate2::Compression;
use std::fs::File;
use std::io::Write;

// Create a valid gzip file to sign
let f = File::create(&msg_path)?;
let mut e = GzEncoder::new(f, Compression::default());
e.write_all(b"compressed content")?;
e.finish()?;

Signer::new()
    .seckey(&sec_path)
    .gzip(true)
    .sign(&msg_path, &sig_path)?;

Implementations§

Source§

impl Signer

Source

pub fn new() -> Self

Create a new Signer.

Source

pub fn tty_handle(self, tty: File) -> Self

Set TTY handle for interactive password prompts.

Source

pub fn seckey(self, path: impl Into<PathBuf>) -> Self

Set secret key path.

Source

pub fn embed(self, embed: bool) -> Self

Set embed mode (signify -e).

If true, creates an embedded signature.

Source

pub fn gzip(self, gzip: bool) -> Self

Set gzip mode (signify -z).

If true, signs a gzip archive.

Source

pub fn key_id(self, key_id: i32) -> Self

Set key ID (for keyring support).

Source

pub fn sign(self, msg_path: &Path, sig_path: &Path) -> Result<()>

Sign a file.

§Errors

Returns errors if I/O, decryption, or signing fails.

Source

pub fn sign_io( &self, msg_path: &Path, sig_path: &Path, msg_file: Option<File>, sig_file: Option<File>, seckey_file: Option<File>, ) -> Result<()>

Sign a message using optional file handles.

Trait Implementations§

Source§

impl Default for Signer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Signer

§

impl RefUnwindSafe for Signer

§

impl Send for Signer

§

impl Sync for Signer

§

impl Unpin for Signer

§

impl UnwindSafe for Signer

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

Source§

type Output = T

Should always be Self
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.