Skip to content

Commit

Permalink
include standard padding in rust generated base64 values
Browse files Browse the repository at this point in the history
  • Loading branch information
timbod7 committed Jun 14, 2023
1 parent 4577fa0 commit 018f3ce
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod custom;

use base64::{prelude::BASE64_STANDARD_NO_PAD, Engine};
use base64::{prelude::BASE64_STANDARD, Engine};
use serde::{Deserialize, Deserializer};
use serde::{Serialize, Serializer};

Expand All @@ -9,7 +9,7 @@ pub struct ByteVector(pub Vec<u8>);

impl ByteVector {
pub fn from_literal(s: &str) -> Self {
let v: Vec<u8> = BASE64_STANDARD_NO_PAD.decode(s).unwrap();
let v: Vec<u8> = BASE64_STANDARD.decode(s).unwrap();
ByteVector(v)
}
}
Expand All @@ -19,7 +19,7 @@ impl Serialize for ByteVector {
where
S: Serializer,
{
let bvs = BASE64_STANDARD_NO_PAD.encode(&self.0);
let bvs = BASE64_STANDARD.encode(&self.0);
bvs.serialize(serializer)
}
}
Expand All @@ -30,7 +30,7 @@ impl<'de> Deserialize<'de> for ByteVector {
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
let v: Vec<u8> = BASE64_STANDARD_NO_PAD
let v: Vec<u8> = BASE64_STANDARD
.decode(s)
.map_err(|_| serde::de::Error::custom("expected a base64 string"))?;
Ok(ByteVector(v))
Expand Down

0 comments on commit 018f3ce

Please sign in to comment.