Struct hashcash::Token[][src]

pub struct Token {
    pub ver: u8,
    pub bits: u32,
    pub date: NaiveDateTime,
    pub resource: String,
    pub ext: String,
    pub rand: Vec<u8>,
    pub counter: Vec<u8>,

Stores a destructured hashcash token by its various components.



impl Token

Given a fully qualified hashcash token string, returns a parsed version of the input.

use hashcash::Token;

let t = "1:4:180606122628:example::OfZIJujxSu6ojd08LI0hLg:AAHz1w";
let token = Token::from_str(t).unwrap();

println!("{:?}", token);

Given a resource string and a difficulty factor, mints a new hashcash::Token and returns it.

use hashcash::Token;

let resource = String::from("");
let bits = 4; // very low difficulty - 20 is normal
let token = Token::new(resource, bits);
println!("Token: {}", token.to_string());

Validates the hashcash::Token, returning any validation errors if not valid.

use hashcash::Token;

let token = "1:4:180606122628:example::OfZIJujxSu6ojd08LI0hLg:AAHz1w";
match Token::from_str(token) {
    Ok(t) => {
        match t.check() {
            Ok(_) => println!("OK"),
            Err(e) => eprintln!("{:?}", e),
    Err(e) => eprintln!("{}", e.message)

Returns a fully qualified hashcash token string suitable for use as a X-Hashcash header value or otherwise.

Trait Implementations

impl Debug for Token

Formats the value using the given formatter. Read more

impl PartialEq for Token

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl Send for Token

impl Sync for Token