summaryrefslogtreecommitdiffstats
path: root/vendor/base64ct/src/alphabet
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/base64ct/src/alphabet')
-rw-r--r--vendor/base64ct/src/alphabet/bcrypt.rs33
-rw-r--r--vendor/base64ct/src/alphabet/crypt.rs29
-rw-r--r--vendor/base64ct/src/alphabet/shacrypt.rs65
-rw-r--r--vendor/base64ct/src/alphabet/standard.rs54
-rw-r--r--vendor/base64ct/src/alphabet/url.rs54
5 files changed, 235 insertions, 0 deletions
diff --git a/vendor/base64ct/src/alphabet/bcrypt.rs b/vendor/base64ct/src/alphabet/bcrypt.rs
new file mode 100644
index 000000000..4227dbfcf
--- /dev/null
+++ b/vendor/base64ct/src/alphabet/bcrypt.rs
@@ -0,0 +1,33 @@
+//! bcrypt Base64 encoding.
+
+use super::{Alphabet, DecodeStep, EncodeStep};
+
+/// bcrypt Base64 encoding.
+///
+/// ```text
+/// ./ [A-Z] [a-z] [0-9]
+/// 0x2e-0x2f, 0x41-0x5a, 0x61-0x7a, 0x30-0x39
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64Bcrypt;
+
+impl Alphabet for Base64Bcrypt {
+ const BASE: u8 = b'.';
+
+ const DECODER: &'static [DecodeStep] = &[
+ DecodeStep::Range(b'.'..=b'/', -45),
+ DecodeStep::Range(b'A'..=b'Z', -62),
+ DecodeStep::Range(b'a'..=b'z', -68),
+ DecodeStep::Range(b'0'..=b'9', 7),
+ ];
+
+ const ENCODER: &'static [EncodeStep] = &[
+ EncodeStep::Apply(b'/', 17),
+ EncodeStep::Apply(b'Z', 6),
+ EncodeStep::Apply(b'z', -75),
+ ];
+
+ const PADDED: bool = false;
+
+ type Unpadded = Self;
+}
diff --git a/vendor/base64ct/src/alphabet/crypt.rs b/vendor/base64ct/src/alphabet/crypt.rs
new file mode 100644
index 000000000..5d97c33ac
--- /dev/null
+++ b/vendor/base64ct/src/alphabet/crypt.rs
@@ -0,0 +1,29 @@
+//! `crypt(3)` Base64 encoding.
+
+use super::{Alphabet, DecodeStep, EncodeStep};
+
+/// `crypt(3)` Base64 encoding.
+///
+/// ```text
+/// [.-9] [A-Z] [a-z]
+/// 0x2e-0x39, 0x41-0x5a, 0x61-0x7a
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64Crypt;
+
+impl Alphabet for Base64Crypt {
+ const BASE: u8 = b'.';
+
+ const DECODER: &'static [DecodeStep] = &[
+ DecodeStep::Range(b'.'..=b'9', -45),
+ DecodeStep::Range(b'A'..=b'Z', -52),
+ DecodeStep::Range(b'a'..=b'z', -58),
+ ];
+
+ const ENCODER: &'static [EncodeStep] =
+ &[EncodeStep::Apply(b'9', 7), EncodeStep::Apply(b'Z', 6)];
+
+ const PADDED: bool = false;
+
+ type Unpadded = Self;
+}
diff --git a/vendor/base64ct/src/alphabet/shacrypt.rs b/vendor/base64ct/src/alphabet/shacrypt.rs
new file mode 100644
index 000000000..ef8d362f9
--- /dev/null
+++ b/vendor/base64ct/src/alphabet/shacrypt.rs
@@ -0,0 +1,65 @@
+//! `crypt(3)` Base64 encoding for sha* family.
+
+use super::{Alphabet, DecodeStep, EncodeStep};
+
+/// `crypt(3)` Base64 encoding for the following schemes.
+/// * sha1_crypt,
+/// * sha256_crypt,
+/// * sha512_crypt,
+/// * md5_crypt
+///
+/// ```text
+/// [.-9] [A-Z] [a-z]
+/// 0x2e-0x39, 0x41-0x5a, 0x61-0x7a
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64ShaCrypt;
+
+impl Alphabet for Base64ShaCrypt {
+ const BASE: u8 = b'.';
+
+ const DECODER: &'static [DecodeStep] = &[
+ DecodeStep::Range(b'.'..=b'9', -45),
+ DecodeStep::Range(b'A'..=b'Z', -52),
+ DecodeStep::Range(b'a'..=b'z', -58),
+ ];
+
+ const ENCODER: &'static [EncodeStep] =
+ &[EncodeStep::Apply(b'9', 7), EncodeStep::Apply(b'Z', 6)];
+
+ const PADDED: bool = false;
+
+ type Unpadded = Self;
+
+ #[inline(always)]
+ fn decode_3bytes(src: &[u8], dst: &mut [u8]) -> i16 {
+ debug_assert_eq!(src.len(), 4);
+ debug_assert!(dst.len() >= 3, "dst too short: {}", dst.len());
+
+ let c0 = Self::decode_6bits(src[0]);
+ let c1 = Self::decode_6bits(src[1]);
+ let c2 = Self::decode_6bits(src[2]);
+ let c3 = Self::decode_6bits(src[3]);
+
+ dst[0] = (c0 | ((c1 & 0x3) << 6)) as u8;
+ dst[1] = ((c1 >> 2) | ((c2 & 0xF) << 4)) as u8;
+ dst[2] = ((c2 >> 4) | (c3 << 2)) as u8;
+
+ ((c0 | c1 | c2 | c3) >> 8) & 1
+ }
+
+ #[inline(always)]
+ fn encode_3bytes(src: &[u8], dst: &mut [u8]) {
+ debug_assert_eq!(src.len(), 3);
+ debug_assert!(dst.len() >= 4, "dst too short: {}", dst.len());
+
+ let b0 = src[0] as i16;
+ let b1 = src[1] as i16;
+ let b2 = src[2] as i16;
+
+ dst[0] = Self::encode_6bits(b0 & 63);
+ dst[1] = Self::encode_6bits(((b1 << 2) | (b0 >> 6)) & 63);
+ dst[2] = Self::encode_6bits(((b2 << 4) | (b1 >> 4)) & 63);
+ dst[3] = Self::encode_6bits(b2 >> 2);
+ }
+}
diff --git a/vendor/base64ct/src/alphabet/standard.rs b/vendor/base64ct/src/alphabet/standard.rs
new file mode 100644
index 000000000..90eab69f1
--- /dev/null
+++ b/vendor/base64ct/src/alphabet/standard.rs
@@ -0,0 +1,54 @@
+//! Standard Base64 encoding.
+
+use super::{Alphabet, DecodeStep, EncodeStep};
+
+/// Standard Base64 encoding with `=` padding.
+///
+/// ```text
+/// [A-Z] [a-z] [0-9] + /
+/// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2b, 0x2f
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64;
+
+impl Alphabet for Base64 {
+ const BASE: u8 = b'A';
+ const DECODER: &'static [DecodeStep] = DECODER;
+ const ENCODER: &'static [EncodeStep] = ENCODER;
+ const PADDED: bool = true;
+ type Unpadded = Base64Unpadded;
+}
+
+/// Standard Base64 encoding *without* padding.
+///
+/// ```text
+/// [A-Z] [a-z] [0-9] + /
+/// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2b, 0x2f
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64Unpadded;
+
+impl Alphabet for Base64Unpadded {
+ const BASE: u8 = b'A';
+ const DECODER: &'static [DecodeStep] = DECODER;
+ const ENCODER: &'static [EncodeStep] = ENCODER;
+ const PADDED: bool = false;
+ type Unpadded = Self;
+}
+
+/// Standard Base64 decoder
+const DECODER: &[DecodeStep] = &[
+ DecodeStep::Range(b'A'..=b'Z', -64),
+ DecodeStep::Range(b'a'..=b'z', -70),
+ DecodeStep::Range(b'0'..=b'9', 5),
+ DecodeStep::Eq(b'+', 63),
+ DecodeStep::Eq(b'/', 64),
+];
+
+/// Standard Base64 encoder
+const ENCODER: &[EncodeStep] = &[
+ EncodeStep::Diff(25, 6),
+ EncodeStep::Diff(51, -75),
+ EncodeStep::Diff(61, -(b'+' as i16 - 0x1c)),
+ EncodeStep::Diff(62, b'/' as i16 - b'+' as i16 - 1),
+];
diff --git a/vendor/base64ct/src/alphabet/url.rs b/vendor/base64ct/src/alphabet/url.rs
new file mode 100644
index 000000000..432edb852
--- /dev/null
+++ b/vendor/base64ct/src/alphabet/url.rs
@@ -0,0 +1,54 @@
+//! URL-safe Base64 encoding.
+
+use super::{Alphabet, DecodeStep, EncodeStep};
+
+/// URL-safe Base64 encoding with `=` padding.
+///
+/// ```text
+/// [A-Z] [a-z] [0-9] - _
+/// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2d, 0x5f
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64Url;
+
+impl Alphabet for Base64Url {
+ const BASE: u8 = b'A';
+ const DECODER: &'static [DecodeStep] = DECODER;
+ const ENCODER: &'static [EncodeStep] = ENCODER;
+ const PADDED: bool = true;
+ type Unpadded = Base64UrlUnpadded;
+}
+
+/// URL-safe Base64 encoding *without* padding.
+///
+/// ```text
+/// [A-Z] [a-z] [0-9] - _
+/// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2d, 0x5f
+/// ```
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct Base64UrlUnpadded;
+
+impl Alphabet for Base64UrlUnpadded {
+ const BASE: u8 = b'A';
+ const DECODER: &'static [DecodeStep] = DECODER;
+ const ENCODER: &'static [EncodeStep] = ENCODER;
+ const PADDED: bool = false;
+ type Unpadded = Self;
+}
+
+/// URL-safe Base64 decoder
+const DECODER: &[DecodeStep] = &[
+ DecodeStep::Range(b'A'..=b'Z', -64),
+ DecodeStep::Range(b'a'..=b'z', -70),
+ DecodeStep::Range(b'0'..=b'9', 5),
+ DecodeStep::Eq(b'-', 63),
+ DecodeStep::Eq(b'_', 64),
+];
+
+/// URL-safe Base64 encoder
+const ENCODER: &[EncodeStep] = &[
+ EncodeStep::Diff(25, 6),
+ EncodeStep::Diff(51, -75),
+ EncodeStep::Diff(61, -(b'-' as i16 - 0x20)),
+ EncodeStep::Diff(62, b'_' as i16 - b'-' as i16 - 1),
+];