diff options
Diffstat (limited to 'vendor/base64ct/tests')
-rw-r--r-- | vendor/base64ct/tests/bcrypt.rs | 68 | ||||
-rw-r--r-- | vendor/base64ct/tests/common/mod.rs | 80 | ||||
-rw-r--r-- | vendor/base64ct/tests/crypt.rs | 68 | ||||
-rw-r--r-- | vendor/base64ct/tests/proptests.proptest-regressions | 10 | ||||
-rw-r--r-- | vendor/base64ct/tests/proptests.rs | 149 | ||||
-rw-r--r-- | vendor/base64ct/tests/shacrypt.rs | 98 | ||||
-rw-r--r-- | vendor/base64ct/tests/standard.rs | 142 | ||||
-rw-r--r-- | vendor/base64ct/tests/url.rs | 128 |
8 files changed, 743 insertions, 0 deletions
diff --git a/vendor/base64ct/tests/bcrypt.rs b/vendor/base64ct/tests/bcrypt.rs new file mode 100644 index 000000000..4ecbfa74d --- /dev/null +++ b/vendor/base64ct/tests/bcrypt.rs @@ -0,0 +1,68 @@ +//! bcrypt Base64 tests + +#[macro_use] +mod common; + +use crate::common::*; +use base64ct::Base64Bcrypt; + +const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\0", + b64: "..", + }, + TestVector { + raw: b"***", + b64: "Igmo", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: ".OGB/.", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "pY0rpYy", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "98989898", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "9999996", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i", + }, + TestVector { + raw: b"\x00\x10\x83\x10Q\x87 \x92\x8B0\xD3\x8FA\x14\x93QU\x97a\x96\x9Bq\ + \xD7\x9F\x82\x18\xA3\x92Y\xA7\xA2\x9A\xAB\xB2\xDB\xAF\xC3\x1C\xB3\ + \xFB\xF0\x00", + b64: "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx89..", + }, +]; + +impl_tests!(Base64Bcrypt); + +#[test] +fn reject_trailing_whitespace() { + let input = "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i\n"; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Bcrypt::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); +} + +#[test] +fn unpadded_reject_trailing_equals() { + let input = "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i="; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Bcrypt::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); +} diff --git a/vendor/base64ct/tests/common/mod.rs b/vendor/base64ct/tests/common/mod.rs new file mode 100644 index 000000000..3910b33b9 --- /dev/null +++ b/vendor/base64ct/tests/common/mod.rs @@ -0,0 +1,80 @@ +//! Common testing functionality + +/// Base64 test vector +pub struct TestVector { + pub raw: &'static [u8], + pub b64: &'static str, +} + +/// Generate test suite for a particular Base64 flavor +#[macro_export] +macro_rules! impl_tests { + ($encoding:ty) => { + use base64ct::{Encoding, Error}; + + #[test] + fn encode_test_vectors() { + let mut buf = [0u8; 1024]; + + for vector in TEST_VECTORS { + let out = <$encoding>::encode(vector.raw, &mut buf).unwrap(); + assert_eq!(<$encoding>::encoded_len(vector.raw), vector.b64.len()); + assert_eq!(vector.b64, &out[..]); + + #[cfg(feature = "alloc")] + { + let out = <$encoding>::encode_string(vector.raw); + assert_eq!(vector.b64, &out[..]); + } + } + } + + #[test] + fn decode_test_vectors() { + let mut buf = [0u8; 1024]; + + for vector in TEST_VECTORS { + let out = <$encoding>::decode(vector.b64, &mut buf).unwrap(); + assert_eq!(vector.raw, &out[..]); + + let n = vector.b64.len(); + buf[..n].copy_from_slice(vector.b64.as_bytes()); + let out = <$encoding>::decode_in_place(&mut buf[..n]).unwrap(); + assert_eq!(vector.raw, out); + + #[cfg(feature = "alloc")] + { + let out = <$encoding>::decode_vec(vector.b64).unwrap(); + assert_eq!(vector.raw, &out[..]); + } + } + } + + #[test] + fn encode_and_decode_various_lengths() { + let data = [b'X'; 64]; + let mut inbuf = [0u8; 1024]; + let mut outbuf = [0u8; 1024]; + + for i in 0..data.len() { + let encoded = <$encoding>::encode(&data[..i], &mut inbuf).unwrap(); + + // Make sure it round trips + let decoded = <$encoding>::decode(encoded, &mut outbuf).unwrap(); + assert_eq!(decoded, &data[..i]); + + let elen = <$encoding>::encode(&data[..i], &mut inbuf).unwrap().len(); + let buf = &mut inbuf[..elen]; + let decoded = <$encoding>::decode_in_place(buf).unwrap(); + assert_eq!(decoded, &data[..i]); + + #[cfg(feature = "alloc")] + { + let encoded = <$encoding>::encode_string(&data[..i]); + let decoded = <$encoding>::decode_vec(&encoded).unwrap(); + assert_eq!(decoded, &data[..i]); + } + } + } + }; +} diff --git a/vendor/base64ct/tests/crypt.rs b/vendor/base64ct/tests/crypt.rs new file mode 100644 index 000000000..cc285f9bd --- /dev/null +++ b/vendor/base64ct/tests/crypt.rs @@ -0,0 +1,68 @@ +//! `crypt(3)` Base64 tests + +#[macro_use] +mod common; + +use crate::common::*; +use base64ct::Base64Crypt; + +const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\0", + b64: "..", + }, + TestVector { + raw: b"***", + b64: "8Wce", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: ".E61/.", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "fOqhfOo", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "zyzyzyzy", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "zzzzzzw", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: "EA2zjEJAQWeXkj6FQw/duYZxBGZfn0FZxjbEEEVvpuY", + }, + TestVector { + raw: b"\x00\x10\x83\x10Q\x87 \x92\x8B0\xD3\x8FA\x14\x93QU\x97a\x96\x9Bq\ + \xD7\x9F\x82\x18\xA3\x92Y\xA7\xA2\x9A\xAB\xB2\xDB\xAF\xC3\x1C\xB3\ + \xFB\xF0\x00", + b64: "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnyz..", + }, +]; + +impl_tests!(Base64Crypt); + +#[test] +fn reject_trailing_whitespace() { + let input = "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i\n"; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Crypt::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); +} + +#[test] +fn unpadded_reject_trailing_equals() { + let input = "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i="; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Crypt::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); +} diff --git a/vendor/base64ct/tests/proptests.proptest-regressions b/vendor/base64ct/tests/proptests.proptest-regressions new file mode 100644 index 000000000..473fcecd2 --- /dev/null +++ b/vendor/base64ct/tests/proptests.proptest-regressions @@ -0,0 +1,10 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc ea4af6a6a3c5feddd17be51d3bb3d863881547acf50b553e76da3f34f8b755d4 # shrinks to base64ish = "" +cc 348d4acf2c3d1e8db3772f5645179e24b50178747469da9709e60800175eef80 # shrinks to bytes = [240, 144, 128, 128, 240, 144, 128, 128, 32, 32, 32, 194, 161, 48, 97, 97, 65, 194, 161, 32, 97, 194, 161, 32, 240, 144, 128, 128, 194, 161, 48, 32, 97, 194, 161, 240, 144, 128, 128, 32, 224, 160, 128, 97, 224, 160, 128, 48, 48, 194, 161, 32, 240, 144, 128, 128, 11, 65, 97, 48, 65, 65, 97, 11, 240, 144, 128, 128, 240, 144, 128, 128, 48, 224, 160, 128, 194, 161, 32, 32, 194, 161, 32, 48, 97, 240, 144, 128, 128, 224, 160, 128, 240, 144, 128, 128, 0, 224, 160, 128, 32, 240, 144, 128, 128, 0, 32, 32, 97, 240, 144, 128, 128, 240, 144, 128, 128, 240, 144, 128, 128, 240, 144, 128, 128, 0, 0, 240, 144, 128, 128, 32, 240, 144, 128, 128, 32, 48, 65, 11, 32, 65, 48, 48, 65, 65, 194, 161, 32, 224, 160, 128, 240, 144, 128, 128, 224, 160, 128, 0, 65, 0, 65, 32, 194, 161, 240, 144, 128, 128, 32, 65, 32, 0, 97, 32, 97, 11, 11, 48, 97, 97, 240, 144, 128, 128, 65, 240, 144, 128, 128, 194, 161], line_width = 10, chunk_size = 163 +cc 0c0ee7f6a60d24431333f5c39c506b818a6c21022e39288619c8f78f29d30b1c # shrinks to bytes = [240, 144, 128, 128, 194, 161, 194, 161, 240, 144, 128, 128, 194, 161, 240, 144, 128, 128, 65, 224, 160, 128, 97, 224, 160, 128, 32, 97, 32, 65, 224, 160, 128, 0, 97, 0, 240, 144, 128, 128, 97, 194, 161, 32, 240, 144, 128, 128, 11, 48, 32, 65, 32, 240, 144, 128, 128, 97, 194, 161, 48, 48, 240, 144, 128, 128, 194, 161, 194, 161, 32, 194, 161, 48, 0, 32, 48, 224, 160, 128, 65, 240, 144, 128, 128, 11, 65, 11, 240, 144, 128, 128, 32, 32, 194, 161, 240, 144, 128, 128, 224, 160, 128, 240, 144, 128, 128, 194, 161, 224, 160, 128, 65, 32, 240, 144, 128, 128, 32, 240, 144, 128, 128, 48, 240, 144, 128, 128, 0, 48, 240, 144, 128, 128, 48, 65, 65, 11, 0, 65, 240, 144, 128, 128, 240, 144, 128, 128, 32, 65, 240, 144, 128, 128, 112, 75, 46, 232, 143, 132, 240, 159, 149, 180, 101, 92, 11, 42, 98, 244, 142, 150, 136, 83, 13, 243, 189, 168, 131, 194, 154, 9, 243, 129, 165, 130, 241, 138, 188, 150, 39, 241, 170, 133, 154, 39, 61, 244, 136, 146, 157, 46, 91, 108, 34, 66, 0, 239, 187, 191, 34, 240, 158, 187, 152, 241, 187, 172, 188, 46, 239, 191, 189, 244, 143, 139, 131, 13, 13, 226, 128, 174, 60, 200, 186, 194, 151, 27, 105, 43, 226, 128, 174, 70, 0, 38, 127, 194, 133, 195, 177, 123, 127, 121, 241, 128, 141, 141, 244, 137, 146, 189, 55, 54, 9, 240, 159, 149, 180, 2, 209, 168, 239, 187, 191, 11, 34, 123, 32, 42, 242, 171, 149, 149, 102, 241, 174, 190, 188, 242, 144, 186, 145, 1, 84, 34, 56, 7, 0, 194, 188, 43, 117, 48, 96, 11, 60, 242, 190, 170, 187, 47, 99, 37, 241, 175, 142, 186, 240, 178, 162, 136, 46, 2, 241, 176, 162, 162, 37, 242, 148, 135, 179, 11, 36, 104, 244, 130, 136, 177], line_width = 24, chunk_size = 240 +cc b6d81102accbff17f00786b06c6040fc59fee8aa087033c9b5604d2a3f246afd # shrinks to bytes = [32, 65, 11, 97, 97, 32, 240, 144, 128, 128, 97, 32, 65, 0, 0, 32, 240, 144, 128, 128, 97, 65, 97, 97, 240, 144, 128, 128, 240, 144, 128, 128, 65, 48, 240, 144, 128, 128, 240, 144, 128, 128, 32, 0, 97, 97, 240, 144, 128, 128, 65, 32, 194, 161, 65, 0, 32, 11, 97, 32, 32, 11, 32, 240, 144, 128, 128, 240, 144, 128, 128, 194, 128, 32, 48, 65, 32, 240, 144, 128, 128, 240, 144, 128, 128, 240, 144, 128, 128, 194, 161, 32, 194, 161, 48, 224, 160, 128, 240, 144, 128, 128, 97, 32, 0, 48, 240, 144, 128, 128, 0, 11, 240, 144, 128, 128, 97, 240, 144, 128, 128, 11, 32, 0, 32, 0, 194, 161, 194, 161, 56, 242, 150, 180, 168, 243, 187, 153, 181, 46, 36, 121, 70, 8, 226, 128, 174, 242, 135, 172, 189, 0, 194, 169, 244, 130, 145, 146, 240, 159, 149, 180, 63, 240, 184, 155, 139, 27, 243, 185, 138, 139, 194, 162, 46, 242, 148, 129, 171, 195, 143, 56, 241, 147, 151, 173, 240, 159, 149, 180, 33, 89, 36, 37, 240, 159, 149, 180, 200, 186, 117, 194, 165, 77, 241, 171, 180, 143, 60, 96, 242, 175, 134, 177, 27, 1, 42, 242, 145, 189, 151, 92, 39, 96, 38, 243, 181, 148, 171, 243, 164, 185, 188, 47, 195, 181, 0, 226, 128, 174, 13, 233, 136, 141, 57, 200, 186, 243, 129, 145, 159, 242, 137, 177, 176, 122, 61, 243, 140, 180, 151, 239, 191, 189, 80, 194, 144, 121, 42, 239, 191, 189, 231, 173, 145, 75, 91, 0, 123, 238, 154, 139, 58, 240, 179, 187, 172, 107, 13, 13, 123, 241, 152, 132, 160, 242, 130, 149, 190, 92, 239, 187, 191, 117, 241, 182, 130, 165, 241, 165, 155, 168, 39, 60, 0, 0, 13, 200, 186, 83, 37, 243, 174, 183, 166, 11, 0, 237, 134, 157, 39, 58, 113, 44, 243, 135, 142, 174, 9, 9, 195, 184, 74, 241, 146, 132, 133, 34, 58, 92, 123, 239, 187, 191, 37, 58, 239, 187, 191, 77, 9, 243, 183, 143, 189, 243, 159, 143, 171, 243, 162, 128, 179, 241, 137, 158, 163, 127, 60, 195, 159, 106, 47, 242, 135, 154, 161, 51, 243, 160, 136, 149, 91, 241, 175, 181, 149, 96, 58, 46, 11, 37, 107, 32, 52, 237, 136, 144, 77, 194, 156, 42, 13, 39, 61, 2, 59, 48, 58, 240, 159, 149, 180, 4, 96, 127, 230, 166, 145, 58, 239, 187, 191, 242, 135, 132, 146, 241, 178, 129, 185, 36], line_width = 118, chunk_size = 147 diff --git a/vendor/base64ct/tests/proptests.rs b/vendor/base64ct/tests/proptests.rs new file mode 100644 index 000000000..eaa5ae3ec --- /dev/null +++ b/vendor/base64ct/tests/proptests.rs @@ -0,0 +1,149 @@ +//! Equivalence tests between `base64` crate and `base64ct`. + +#![cfg(feature = "std")] + +use base64ct::{Base64 as Base64ct, Encoding}; +use proptest::{prelude::*, string::*}; +use std::iter; + +/// Incremental Base64 decoder. +type Decoder<'a> = base64ct::Decoder<'a, Base64ct>; + +/// Incremental Base64 encoder. +type Encoder<'a> = base64ct::Encoder<'a, Base64ct>; + +proptest! { + /// Ensure `base64ct` decodes data encoded by `base64` ref crate + #[test] + fn decode_equiv(bytes in bytes_regex(".{0,256}").unwrap()) { + let encoded = base64::encode(&bytes); + let decoded = Base64ct::decode_vec(&encoded); + prop_assert_eq!(Ok(bytes), decoded); + } + + /// Ensure that `base64ct`'s incremental decoder is able to decode randomly + /// generated inputs encoded by the `base64` ref crate + #[test] + fn decode_incremental(bytes in bytes_regex(".{1,256}").unwrap(), chunk_size in 1..256usize) { + let encoded = base64::encode(&bytes); + let chunk_size = match chunk_size % bytes.len() { + 0 => 1, + n => n + }; + + let mut buffer = [0u8; 384]; + let mut decoder = Decoder::new(encoded.as_bytes()).unwrap(); + let mut remaining_len = decoder.remaining_len(); + + for chunk in bytes.chunks(chunk_size) { + prop_assert!(!decoder.is_finished()); + + let decoded = decoder.decode(&mut buffer[..chunk.len()]); + prop_assert_eq!(Ok(chunk), decoded); + + remaining_len -= decoded.unwrap().len(); + prop_assert_eq!(remaining_len, decoder.remaining_len()); + } + + prop_assert!(decoder.is_finished()); + prop_assert_eq!(decoder.remaining_len(), 0); + } + + #[test] + fn decode_incremental_wrapped( + bytes in bytes_regex(".{1,256}").unwrap(), + line_width in 4..128usize, + chunk_size in 1..256usize + ) { + for line_ending in ["\r", "\n", "\r\n"] { + let encoded = base64::encode(&bytes); + + let mut encoded_wrapped = Vec::new(); + let mut lines = encoded.as_bytes().chunks_exact(line_width); + + for line in &mut lines { + encoded_wrapped.extend_from_slice(line); + encoded_wrapped.extend_from_slice(line_ending.as_bytes()); + } + + let last = lines.remainder(); + + if last.is_empty() { + encoded_wrapped.truncate(encoded_wrapped.len() - line_ending.len()); + } else { + encoded_wrapped.extend_from_slice(last); + } + + let chunk_size = match chunk_size % bytes.len() { + 0 => 1, + n => n + }; + + let mut buffer = [0u8; 384]; + let mut decoder = Decoder::new_wrapped(&encoded_wrapped, line_width).unwrap(); + let mut remaining_len = decoder.remaining_len(); + + for chunk in bytes.chunks(chunk_size) { + prop_assert!(!decoder.is_finished()); + + let decoded = decoder.decode(&mut buffer[..chunk.len()]); + prop_assert_eq!(Ok(chunk), decoded); + + remaining_len -= decoded.unwrap().len(); + prop_assert_eq!(remaining_len, decoder.remaining_len()); + } + + prop_assert!(decoder.is_finished()); + prop_assert_eq!(decoder.remaining_len(), 0); + } + } + + /// Ensure `base64ct` and `base64` ref crate decode randomly generated + /// inputs equivalently. + /// + /// Inputs are selected to be valid characters in the standard Base64 + /// padded alphabet, but are not necessarily valid Base64. + #[test] + fn decode_random(base64ish in string_regex("[A-Za-z0-9+/]{0,256}").unwrap()) { + let base64ish_padded = match base64ish.len() % 4 { + 0 => base64ish, + n => { + let padding_len = 4 - n; + base64ish + &iter::repeat("=").take(padding_len).collect::<String>() + } + }; + + let decoded_ct = Base64ct::decode_vec(&base64ish_padded).ok(); + let decoded_ref = base64::decode(&base64ish_padded).ok(); + prop_assert_eq!(decoded_ct, decoded_ref); + } + + /// Ensure `base64ct` and the `base64` ref crate encode randomly generated + /// inputs equivalently. + #[test] + fn encode_equiv(bytes in bytes_regex(".{0,256}").unwrap()) { + let encoded_ct = Base64ct::encode_string(&bytes); + let encoded_ref = base64::encode(&bytes); + prop_assert_eq!(encoded_ct, encoded_ref); + } + + /// Ensure that `base64ct`'s incremental encoder is able to encode randomly + /// generated inputs which match what's encoded by the `base64` ref crate + #[test] + fn encode_incremental(bytes in bytes_regex(".{1,256}").unwrap(), chunk_size in 1..256usize) { + let expected = base64::encode(&bytes); + let chunk_size = match chunk_size % bytes.len() { + 0 => 1, + n => n + }; + + let mut buffer = [0u8; 1024]; + let mut encoder = Encoder::new(&mut buffer).unwrap(); + + for chunk in bytes.chunks(chunk_size) { + encoder.encode(chunk).unwrap(); + } + + prop_assert_eq!(expected, encoder.finish().unwrap()); + } +} diff --git a/vendor/base64ct/tests/shacrypt.rs b/vendor/base64ct/tests/shacrypt.rs new file mode 100644 index 000000000..a69f7c7d1 --- /dev/null +++ b/vendor/base64ct/tests/shacrypt.rs @@ -0,0 +1,98 @@ +//! `crypt(3)` Base64 tests + +#[macro_use] +mod common; + +use crate::common::*; +use base64ct::Base64ShaCrypt; + +const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\x55", + b64: "J/", + }, + TestVector { + raw: b"\x55\xaa", + b64: "Jd8", + }, + TestVector { + raw: b"\x55\xaa\x55", + b64: "JdOJ", + }, + TestVector { + raw: b"\x55\xaa\x55\xaa", + b64: "JdOJe0", + }, + TestVector { + raw: b"\x55\xaa\x55\xaa\x55", + b64: "JdOJeK3", + }, + TestVector { + raw: b"\x55\xaa\x55\xaa\x55\xaa", + b64: "JdOJeKZe", + }, + TestVector { + raw: b"\x55\xaa\x55\xaf", + b64: "JdOJj0", + }, + TestVector { + raw: b"\x55\xaa\x55\xaa\x5f", + b64: "JdOJey3", + }, + TestVector { + raw: b"\0", + b64: "..", + }, + TestVector { + raw: b"***", + b64: "ecW8", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: "/6k.2.", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "hqOfhq8", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "zzizzziz", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "zzzzzzD", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: ".3wDxK.Hmdmc09T2n/QOebITpYmOAHGNqbDo/VkSLb8", + }, + TestVector { + raw: b"@ \x0cDa\x1cH\xa2,L\xe3<P$MTe]X\xa6m\\\xe7}`(\x8edi\x9eh\xaa\xael\xeb\xbep,\xcf\xfe\x0f\x00", + b64: "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnyz..", + }, +]; + +impl_tests!(Base64ShaCrypt); + +#[test] +fn reject_trailing_whitespace() { + let input = "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i\n"; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64ShaCrypt::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); +} + +#[test] +fn unpadded_reject_trailing_equals() { + let input = "OKC9tOTKagohutGPa6/n4ij7LQjpxAPj7tlOOOf5z4i="; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64ShaCrypt::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); +} diff --git a/vendor/base64ct/tests/standard.rs b/vendor/base64ct/tests/standard.rs new file mode 100644 index 000000000..e2b9daa37 --- /dev/null +++ b/vendor/base64ct/tests/standard.rs @@ -0,0 +1,142 @@ +//! Standard Base64 tests + +#[macro_use] +mod common; + +/// Standard Base64 with `=` padding +mod padded { + use crate::common::*; + use base64ct::Base64; + + const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\0", + b64: "AA==", + }, + TestVector { + raw: b"***", + b64: "Kioq", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: "AQIDBA==", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "ra2tra0=", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "/+/+/+/+", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "//////8=", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: "QME/vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k=", + }, + TestVector { + raw: b"\x00\x10\x83\x10Q\x87 \x92\x8B0\xD3\x8FA\x14\x93QU\x97a\x96\x9Bq\ + \xD7\x9F\x82\x18\xA3\x92Y\xA7\xA2\x9A\xAB\xB2\xDB\xAF\xC3\x1C\xB3\ + \xFB\xF0\x00", + b64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/AA", + }, + ]; + + impl_tests!(Base64); + + #[test] + fn reject_trailing_whitespace() { + let input = "QME/vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k\n"; + let mut buf = [0u8; 1024]; + assert_eq!(Base64::decode(input, &mut buf), Err(Error::InvalidEncoding)); + } + + #[test] + fn reject_invalid_padding() { + let input = "AA/="; + let mut buf = [0u8; 1024]; + assert_eq!(Base64::decode(input, &mut buf), Err(Error::InvalidEncoding)); + } +} + +/// Standard Base64 *without* padding +mod unpadded { + use crate::common::*; + use base64ct::Base64Unpadded; + + const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\0", + b64: "AA", + }, + TestVector { + raw: b"***", + b64: "Kioq", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: "AQIDBA", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "ra2tra0", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "/+/+/+/+", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "//////8", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: "QME/vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k", + }, + TestVector { + raw: b"\x00\x10\x83\x10Q\x87 \x92\x8B0\xD3\x8FA\x14\x93QU\x97a\x96\x9Bq\ + \xD7\x9F\x82\x18\xA3\x92Y\xA7\xA2\x9A\xAB\xB2\xDB\xAF\xC3\x1C\xB3\ + \xFB\xF0\x00", + b64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/AA", + }, + ]; + + impl_tests!(Base64Unpadded); + + #[test] + fn reject_trailing_whitespace() { + let input = "EA2zjEJAQWeXkj6FQw/duYZxBGZfn0FZxjbEEEVvpuY\n"; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Unpadded::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); + } + + #[test] + fn unpadded_reject_trailing_equals() { + let input = "EA2zjEJAQWeXkj6FQw/duYZxBGZfn0FZxjbEEEVvpuY="; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Unpadded::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); + } + + #[test] + fn reject_non_canonical_encoding() { + let input = "Mi"; + let mut buf = [0u8; 8]; + assert_eq!( + Base64Unpadded::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); + } +} diff --git a/vendor/base64ct/tests/url.rs b/vendor/base64ct/tests/url.rs new file mode 100644 index 000000000..1d75ce959 --- /dev/null +++ b/vendor/base64ct/tests/url.rs @@ -0,0 +1,128 @@ +//! URL-safe Base64 tests + +#[macro_use] +mod common; + +/// URL-safe Base64 with `=` padding +mod padded { + use crate::common::*; + use base64ct::Base64Url; + + const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\0", + b64: "AA==", + }, + TestVector { + raw: b"***", + b64: "Kioq", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: "AQIDBA==", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "ra2tra0=", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "_-_-_-_-", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "______8=", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: "QME_vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k=", + }, + TestVector { + raw: b"\x00\x10\x83\x10Q\x87 \x92\x8B0\xD3\x8FA\x14\x93QU\x97a\x96\x9Bq\ + \xD7\x9F\x82\x18\xA3\x92Y\xA7\xA2\x9A\xAB\xB2\xDB\xAF\xC3\x1C\xB3\ + \xFB\xF0\x00", + b64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_AA", + }, + ]; + + impl_tests!(Base64Url); + + #[test] + fn reject_trailing_whitespace() { + let input = "QME/vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k\n"; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64Url::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); + } +} + +/// URL-safe Base64 *without* padding +mod unpadded { + use crate::common::*; + use base64ct::Base64UrlUnpadded; + + const TEST_VECTORS: &[TestVector] = &[ + TestVector { raw: b"", b64: "" }, + TestVector { + raw: b"\0", + b64: "AA", + }, + TestVector { + raw: b"***", + b64: "Kioq", + }, + TestVector { + raw: b"\x01\x02\x03\x04", + b64: "AQIDBA", + }, + TestVector { + raw: b"\xAD\xAD\xAD\xAD\xAD", + b64: "ra2tra0", + }, + TestVector { + raw: b"\xFF\xEF\xFE\xFF\xEF\xFE", + b64: "_-_-_-_-", + }, + TestVector { + raw: b"\xFF\xFF\xFF\xFF\xFF", + b64: "______8", + }, + TestVector { + raw: b"\x40\xC1\x3F\xBD\x05\x4C\x72\x2A\xA3\xC2\xF2\x11\x73\xC0\x69\xEA\ + \x49\x7D\x35\x29\x6B\xCC\x24\x65\xF6\xF9\xD0\x41\x08\x7B\xD7\xA9", + b64: "QME_vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k", + }, + TestVector { + raw: b"\x00\x10\x83\x10Q\x87 \x92\x8B0\xD3\x8FA\x14\x93QU\x97a\x96\x9Bq\ + \xD7\x9F\x82\x18\xA3\x92Y\xA7\xA2\x9A\xAB\xB2\xDB\xAF\xC3\x1C\xB3\ + \xFB\xF0\x00", + b64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_AA", + }, + ]; + + impl_tests!(Base64UrlUnpadded); + + #[test] + fn reject_trailing_whitespace() { + let input = "QME/vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k\n"; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64UrlUnpadded::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); + } + + #[test] + fn unpadded_reject_trailing_equals() { + let input = "QME_vQVMciqjwvIRc8Bp6kl9NSlrzCRl9vnQQQh716k="; + let mut buf = [0u8; 1024]; + assert_eq!( + Base64UrlUnpadded::decode(input, &mut buf), + Err(Error::InvalidEncoding) + ); + } +} |