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.
Fields
ver: u8
bits: u32
date: NaiveDateTime
resource: String
ext: String
rand: Vec<u8>
counter: Vec<u8>
Methods
impl Token
[src]
impl Token
pub fn from_str(stamp: &str) -> Result<Token, ParseError>
[src]
pub fn from_str(stamp: &str) -> Result<Token, ParseError>
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);
pub fn new(resource: String, bits: u32) -> Token
[src]
pub fn new(resource: String, bits: u32) -> Token
Given a resource string and a difficulty factor, mints a new
hashcash::Token
and returns it.
use hashcash::Token; let resource = String::from("test@hashcash.rs"); let bits = 4; // very low difficulty - 20 is normal let token = Token::new(resource, bits); println!("Token: {}", token.to_string());
pub fn check(&self) -> Result<&Self, CheckError>
[src]
pub fn check(&self) -> Result<&Self, CheckError>
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) }
pub fn to_string(&self) -> String
[src]
pub fn to_string(&self) -> String
Returns a fully qualified hashcash token string suitable for use as a
X-Hashcash
header value or otherwise.
Trait Implementations
impl Debug for Token
[src]
impl Debug for Token
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Token
[src]
impl PartialEq for Token