rust-base58 0.0.4

Simple library for converting to and from base-58 strings.
Documentation
b0VIM 7.4#��U�SF$nhammega~nham/code/mine/rust-base58/src/base58.rsutf-8
3210#"! UtpSUfkad^�S�����vuG
���X�
L

��s4210���vTRQ+�
�
�
c
Y
S
Q
P
(
�	�	�	�	�	�	�	�	f	@	:	8	7		��uG���yL���>������<%���������YD������Z���:��        let radix = 58.to_biguint().unwrap();    fn to_base58(&self) -> String {    // without reading the rest    // so by reading "1", no way to know if first character should be 5 or 6    //   [1, 34] should be "61"    //   [1, 33] should be "5z"    // the slice and create parts of the base58 string. Example:    // (big) int before creating the string. There's no way to incrementally read    // This function has to read in the entire byte slice and convert it to aimpl ToBase58 for [u8] {}    fn to_base58(&self) -> String;    /// string.    /// Converts the value of `self` to a base-58 value, returning the ownedpub trait ToBase58 {/// A trait for converting a value to base58 encoding.}    }        Ok(r)        }              // TOD            // TODO: use append when it becomes stable        if x > Zero::zero() {        }            r.push(0);        for _ in self.iter().take_while(|&x| *x == BTC_ALPHA[0]) {        let mut r = Vec::with_capacity(self.len());        }            rad_mult = &rad_mult * &radix;            }                None => return Err(InvalidBase58Byte(self[idx], idx))                Some(i) => { x = x + i.to_biguint().unwrap() * &rad_mult; },            match first_idx {                                     .map(|x| x.0);                                     .find(|x| *x.1 == byte)                                     .enumerate()            let first_idx = BTC_ALPHA.iter()        for (idx, &byte) in self.iter().enumerate().rev() {        // Convert the base58 string to a BigUint `x`        let mut rad_mult: BigUint = One::one();        let mut x: BigUint = Zero::zero();        let radix = 58.to_biguint().unwrap();    fn from_base58(&self) -> Result<Vec<u8>, FromBase58Error> {    // are overloadable    // TODO: fix some of the below when the binary assignment operators +=, *=impl FromBase58 for [u8] {}    }        self.as_bytes().from_base58()    fn from_base58(&self) -> Result<Vec<u8>, FromBase58Error> {impl FromBase58 for str {}    }        fmt::Debug::fmt(&self, f)    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {impl fmt::Display for FromBase58Error {}    }        }                write!(f, "Invalid character '{}' at position {}", ch, idx),            InvalidBase58Byte(ch, idx) =>        match *self {    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {impl fmt::Debug for FromBase58Error {}    InvalidBase58Byte(u8, usize),    /// The input contained a character not part of the base58 alphabetpub enum FromBase58Error {#[derive(Clone, Copy)]/// Errors that can occur when decoding a base58-encoded string}    fn from_base58(&self) -> Result<Vec<u8>, FromBase58Error>;    /// into an owned vector of bytes, returning the vector.    /// Converts the value of `self`, interpreted as base58 encoded data,pub trait FromBase58 {// PR though: https://github.com/rust-lang/rust/pull/23606// TODO: This should incorporate the alphabet used as an associated constant.  However, associated constants are not implemented in Rust yet. There is a/// A trait for converting base58-encoded values                                      ABCDEFGHJKLMNPQRSTUVWXYZ";                                      abcdefghijkmnopqrstuvwxyz\static FLICKR_ALPHA: &'static[u8] = b"123456789\                                   abcdefghijkmnopqrstuvwxyz";                                   ABCDEFGHJKLMNPQRSTUVWXYZ\static BTC_ALPHA: &'static[u8] = b"123456789\pub use self::FromBase58Error::*;use std::fmt;use num::traits::ToPrimitive;use num::{BigUint, Zero, One};use num::bigint::ToBigUint;ad:�f���U/���{d<6432%�
�
�
�
�
W
 
��{>�s�
�
�
�
�
�
�
}
T
'
�	�	�	o	>		��{uth>�{4.-!���T(���h'�����R�����vQP6���e>����}    }        }                       v);                        .unwrap(),                        .from_base58()            assert_eq!(v.to_base58()                                .collect::<Vec<_>>();            let v = thread_rng().gen_iter::<u8>().take(times)            let times = thread_rng().gen_range(1, 100);        for _ in 0..200 {        use rand::{thread_rng, Rng};    fn test_base58_random() {    #[test]    }        assert_eq!(b"\0\0\0\0abc".to_base58(), "1111ZiCa");        assert_eq!(b"\0\0\0abc".to_base58(), "111ZiCa");        assert_eq!(b"\0\0abc".to_base58(), "11ZiCa");        assert_eq!(b"\0abc".to_base58(), "1ZiCa");    fn test_to_base58_initial_zeros() {    #[test]    }        assert_eq!(b"abcdefghijklmnopqrstuvwxyz".to_base58(), "3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f");        assert_eq!(b"1234598760".to_base58(), "3mJr7AoUXx2Wqd");        assert_eq!(b"abc".to_base58(), "ZiCa");        assert_eq!(&[49, 49].to_base58(), "4k8");        assert_eq!(&[45, 49].to_base58(), "4SU");        assert_eq!(&[57].to_base58(), "z");        assert_eq!(&[49].to_base58(), "r");        assert_eq!(&[48].to_base58(), "q");        assert_eq!(&[45].to_base58(), "n");        assert_eq!(&[32].to_base58(), "Z");        assert_eq!(b"".to_base58(), "");    fn test_to_base58_basic() {    #[test]    }        assert_eq!("1111ZiCa".from_base58().unwrap(), b"\0\0\0\0abc");        assert_eq!("111ZiCa".from_base58().unwrap(), b"\0\0\0abc");        assert_eq!("11ZiCa".from_base58().unwrap(), b"\0\0abc");        assert_eq!("1ZiCa".from_base58().unwrap(), b"\0abc");    fn test_from_base58_initial_zeros() {    #[test]    }        assert!("t$@mX<*".from_base58().is_err());        assert!("s!5<".from_base58().is_err());        assert!("4kl8".from_base58().is_err());        assert!("3sNI".from_base58().is_err());        assert!("O3yxU".from_base58().is_err());        assert!("3mJr0".from_base58().is_err());        assert!("l".from_base58().is_err());        assert!("I".from_base58().is_err());        assert!("O".from_base58().is_err());        assert!("0".from_base58().is_err());    fn test_from_base58_invalid_char() {    #[test]    }        assert_eq!(b"ZiCa".from_base58().unwrap(), b"abc");    fn test_from_base58_bytes() {    #[test]    }        assert_eq!("3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f".from_base58().unwrap(), b"abcdefghijklmnopqrstuvwxyz");        assert_eq!("3mJr7AoUXx2Wqd".from_base58().unwrap(), b"1234598760");        assert_eq!("ZiCa".from_base58().unwrap(), &[97, 98, 99]);        assert_eq!("4k8".from_base58().unwrap(), &[49, 49]);        assert_eq!("4SU".from_base58().unwrap(), &[45, 49]);        assert_eq!("z".from_base58().unwrap(), &[57]);        assert_eq!("r".from_base58().unwrap(), &[49]);        assert_eq!("q".from_base58().unwrap(), &[48]);        assert_eq!("n".from_base58().unwrap(), &[45]);        assert_eq!("Z".from_base58().unwrap(), &[32]);        assert_eq!("".from_base58().unwrap(), b"");    fn test_from_base58_basic() {    #[test]    use base58::{FromBase58, ToBase58};mod tests {#[cfg(test)]}    }        String::from_utf8(ans).unwrap()        ans.reverse();        }            ans.push(BTC_ALPHA[0]);        for _ in self.iter().take_while(|&x| *x == 0) {        // take care of leading zeros        }            x = &x / &radix;            ans.push(BTC_ALPHA[rem]);            let rem = (&x % &radix).to_usize().unwrap();        while x > Zero::zero() {        let mut ans = vec![];        let mut x = BigUint::from_bytes_be(&self);ads���������k�����/�
�
�
a
A

�        let radix = 58.to_biguint().unwrap();    fn to_base58(&self) -> String {    // without reading the rest    // so by reading "1", no way to know if first character should be 5 or 6    //   [1, 34] should be "61"    //   [1, 33] should be "5z"    // the slice and create parts of the base58 string. Example:    // (big) int before creating the string. There's no way to incrementally read    // This function has to read in the entire byte slice and convert it to aimpl ToBase58 for [u8] {}    fn to_base58(&self) -> String;    /// string.    /// Converts the value of `self` to a base-58 value, returning the ownedpub trait ToBase58 {/// A trait for converting a value to base58 encoding.}    }        Ok(r)        }            r.extend(x.to_bytes_be());