Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps with data-encoding crate #187

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
base16 = { version = "0.2.1", default-features = false }
base64 = { version = "0.13.0", default-features = false }
# base64 = { version = "0.21.0", default-features = false }
data-encoding = { version = "2.3.3", default-features = false }
chrono = { version = "0.4.19", optional = true }
clap = { version = "3.1.6", optional = true, features = ["derive"] }
codespan-reporting = "0.11.1"
Expand Down Expand Up @@ -54,7 +55,7 @@ wasm-bindgen-test = "0.3.25"

[features]
default = ["std", "ast-span", "ast-comments", "json", "cbor", "additional-controls", "ast-parent"]
std = ["base16/alloc", "base64/alloc", "serde_json", "ciborium", "serde", "chrono", "wasm-bindgen", "serde-wasm-bindgen", "clap", "crossterm", "uriparse", "base64-url", "regex-syntax"]
std = ["base16/alloc", "data-encoding/alloc", "serde_json", "ciborium", "serde", "chrono", "wasm-bindgen", "serde-wasm-bindgen", "clap", "crossterm", "uriparse", "base64-url", "regex-syntax"]
lsp = ["std"]
additional-controls = []
ast-span = []
Expand Down
12 changes: 7 additions & 5 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ impl From<(&str, Position, base16::DecodeError)> for Error {
}
}

impl From<(&str, Position, base64::DecodeError)> for Error {
fn from(e: (&str, Position, base64::DecodeError)) -> Self {
impl From<(&str, Position, data_encoding::DecodeError)> for Error {
fn from(e: (&str, Position, data_encoding::DecodeError)) -> Self {
Error {
error_type: LexerErrorType::BASE64(e.2.to_string()),
input: e.0.to_string(),
Expand Down Expand Up @@ -604,9 +604,11 @@ impl<'a> Lexer<'a> {
// Ensure that the byte string has been properly
// encoded
let bs = self.read_prefixed_byte_string(idx)?;
let mut buf = [0u8; 1024];
return base64::decode_config_slice(&bs, base64::URL_SAFE, &mut buf)
.map_err(|e| (self.str_input, self.position, e).into())
let mut buf =
vec![0; data_encoding::BASE64.decode_len(bs.len()).unwrap()];
return data_encoding::BASE64URL
.decode_mut(&bs, &mut buf)
.map_err(|e| (self.str_input, self.position, e.error).into())
.map(|_| {
self.position.range = (token_offset, self.position.index + 1);

Expand Down
44 changes: 12 additions & 32 deletions src/validator/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn cat_operation<'a>(
// "testing" .cat b64'MTIz'
Type2::B64ByteString {
value: controller, ..
} => match base64::decode_config(controller, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(controller) {
Ok(controller) => match String::from_utf8(controller) {
Ok(controller) => {
if is_dedent {
Expand Down Expand Up @@ -266,7 +266,7 @@ pub fn cat_operation<'a>(
// 'testing' .cat b64'MTIz'
Type2::B64ByteString {
value: controller, ..
} => match base64::decode_config(controller, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(controller) {
Ok(controller) => match String::from_utf8(controller) {
Ok(controller) => {
let value = value.trim_start_matches('\'').trim_end_matches('\'');
Expand Down Expand Up @@ -382,7 +382,7 @@ pub fn cat_operation<'a>(
// h'74657374696E67' .cat b64'MTIz'
Type2::B64ByteString {
value: controller, ..
} => match base64::decode_config(controller, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(controller) {
Ok(controller) => {
let controller = base16::encode_lower(&controller);
let concat = if is_dedent {
Expand Down Expand Up @@ -421,7 +421,7 @@ pub fn cat_operation<'a>(
// b64'dGVzdGluZw==' .cat "123"
Type2::TextValue {
value: controller, ..
} => match base64::decode_config(value, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(value) {
Ok(value) => {
let concat = if is_dedent {
[
Expand All @@ -434,12 +434,7 @@ pub fn cat_operation<'a>(
};

literals.push(
ByteValue::B64(
base64::encode_config(concat, base64::URL_SAFE)
.into_bytes()
.into(),
)
.into(),
ByteValue::B64(data_encoding::BASE64URL.encode(&concat).into_bytes().into()).into(),
)
}
Err(e) => return Err(format!("target is invalid base64: {}", e)),
Expand All @@ -460,7 +455,7 @@ pub fn cat_operation<'a>(
// b64'dGVzdGluZw==' .cat '123'
Type2::UTF8ByteString {
value: controller, ..
} => match base64::decode_config(value, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(value) {
Ok(value) => {
let concat = if is_dedent {
[
Expand All @@ -473,20 +468,15 @@ pub fn cat_operation<'a>(
};

literals.push(
ByteValue::B64(
base64::encode_config(concat, base64::URL_SAFE)
.into_bytes()
.into(),
)
.into(),
ByteValue::B64(data_encoding::BASE64URL.encode(&concat).into_bytes().into()).into(),
)
}
Err(e) => return Err(format!("target is invalid base64: {}", e)),
},
// b64'dGVzdGluZw==' .cat h'313233'
Type2::B16ByteString {
value: controller, ..
} => match base64::decode_config(value, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(value) {
Ok(value) => match base16::decode(controller) {
Ok(controller) => {
let concat = if is_dedent {
Expand All @@ -499,12 +489,7 @@ pub fn cat_operation<'a>(
[&value[..], &controller[..]].concat()
};
literals.push(
ByteValue::B64(
base64::encode_config(concat, base64::URL_SAFE)
.into_bytes()
.into(),
)
.into(),
ByteValue::B64(data_encoding::BASE64URL.encode(&concat).into_bytes().into()).into(),
)
}
Err(e) => return Err(format!("controller is invalid base16: {}", e)),
Expand All @@ -514,8 +499,8 @@ pub fn cat_operation<'a>(
// b64'dGVzdGluZw==' .cat b64'MTIz'
Type2::B64ByteString {
value: controller, ..
} => match base64::decode_config(value, base64::URL_SAFE) {
Ok(value) => match base64::decode_config(controller, base64::URL_SAFE) {
} => match data_encoding::BASE64URL.decode(value) {
Ok(value) => match data_encoding::BASE64URL.decode(controller) {
Ok(controller) => {
let concat = if is_dedent {
[
Expand All @@ -527,12 +512,7 @@ pub fn cat_operation<'a>(
[&value[..], &controller[..]].concat()
};
literals.push(
ByteValue::B64(
base64::encode_config(concat, base64::URL_SAFE)
.into_bytes()
.into(),
)
.into(),
ByteValue::B64(data_encoding::BASE64URL.encode(&concat).into_bytes().into()).into(),
)
}
Err(e) => return Err(format!("controller is invalid base64: {}", e)),
Expand Down