Skip to content

Commit

Permalink
auto merge of #6796 : sfackler/rust/FromBase64-type-fix, r=bstrie
Browse files Browse the repository at this point in the history
Previously, FromBase64 was only implemented on ~[u8] and ~str when
any pointer would do. The implementations of FromBase64 are now
consistent with the implementations of ToBase64.
  • Loading branch information
bors committed May 29, 2013
2 parents 844b5cf + b1e7d49 commit a037fa4
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/libextra/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub trait FromBase64 {
fn from_base64(&self) -> ~[u8];
}

impl FromBase64 for ~[u8] {
impl<'self> FromBase64 for &'self [u8] {
/**
* Convert base64 `u8` vector into u8 byte values.
* Every 4 encoded characters is converted into 3 octets, modulo padding.
Expand Down Expand Up @@ -188,7 +188,7 @@ impl FromBase64 for ~[u8] {
}
}

impl FromBase64 for ~str {
impl<'self> FromBase64 for &'self str {
/**
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
* to the byte values it encodes.
Expand Down Expand Up @@ -227,23 +227,23 @@ mod tests {

#[test]
fn test_to_base64() {
assert_eq!((~"").to_base64(), ~"");
assert!((~"f").to_base64() == ~"Zg==");
assert_eq!((~"fo").to_base64(), ~"Zm8=");
assert_eq!((~"foo").to_base64(), ~"Zm9v");
assert!((~"foob").to_base64() == ~"Zm9vYg==");
assert_eq!((~"fooba").to_base64(), ~"Zm9vYmE=");
assert_eq!((~"foobar").to_base64(), ~"Zm9vYmFy");
assert_eq!("".to_base64(), ~"");
assert_eq!("f".to_base64(), ~"Zg==");
assert_eq!("fo".to_base64(), ~"Zm8=");
assert_eq!("foo".to_base64(), ~"Zm9v");
assert_eq!("foob".to_base64(), ~"Zm9vYg==");
assert_eq!("fooba".to_base64(), ~"Zm9vYmE=");
assert_eq!("foobar".to_base64(), ~"Zm9vYmFy");
}

#[test]
fn test_from_base64() {
assert_eq!((~"").from_base64(), str::to_bytes(""));
assert!((~"Zg==").from_base64() == str::to_bytes("f"));
assert_eq!((~"Zm8=").from_base64(), str::to_bytes("fo"));
assert_eq!((~"Zm9v").from_base64(), str::to_bytes("foo"));
assert!((~"Zm9vYg==").from_base64() == str::to_bytes("foob"));
assert_eq!((~"Zm9vYmE=").from_base64(), str::to_bytes("fooba"))
assert_eq!((~"Zm9vYmFy").from_base64(), str::to_bytes("foobar"));
assert_eq!("".from_base64(), str::to_bytes(""));
assert_eq!("Zg==".from_base64(), str::to_bytes("f"));
assert_eq!("Zm8=".from_base64(), str::to_bytes("fo"));
assert_eq!("Zm9v".from_base64(), str::to_bytes("foo"));
assert_eq!("Zm9vYg==".from_base64(), str::to_bytes("foob"));
assert_eq!("Zm9vYmE=".from_base64(), str::to_bytes("fooba"))
assert_eq!("Zm9vYmFy".from_base64(), str::to_bytes("foobar"));
}
}

0 comments on commit a037fa4

Please sign in to comment.