Skip to content

Commit

Permalink
fix: deserialize tokens with missing padding
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Feb 16, 2024
1 parent 0e0316b commit 1fca7d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions moksha-core/src/fixtures/token_no_pad60.cashu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHA6Ly8xMjcuMC4wLjE6MzMzOCIsInByb29mcyI6W3siYW1vdW50Ijo0LCJzZWNyZXQiOiJzR3Z3OVZwalpqNGQ0YnFFU3FvQzdwTWEiLCJDIjoiMDM3YmQ2MGY2YWE1ZTE5ZjZhOWVjMzU5MjlkOGViN2E2Yzk1Y2YyOTM5NTlmMzMzNTQzYWQ5MWIxNTkyNWU2OTE1IiwiaWQiOiJtUjlQSjNNempMMXkifSx7ImFtb3VudCI6OCwic2VjcmV0IjoiQjJqNmw4Z1VUYjIxR0hqMFRnbUNRUjZHIiwiQyI6IjAyOTQzYmI0MWY4MmY3MGE2MWIwMzM0ZGU1YjJjZjNmYzc0YmI2ZTlhZTY5OWVlMzc4YjYyMzc3ZTVhMWJiZmM5ZCIsImlkIjoibVI5UEozTXpqTDF5In0seyJhbW91bnQiOjE2LCJzZWNyZXQiOiJ2SFRHbGJoRXFBQUdEUVBteFBkczc1MFkiLCJDIjoiMDI4NDU0OGJkN2FiNjhmNTIyNzdkOTQxYTgwN2JmZjJlZWI4ZjNmY2EzYmVlODY2ODgxN2RjYTg3MGJhOGQxYWJkIiwiaWQiOiJtUjlQSjNNempMMXkifSx7ImFtb3VudCI6MzIsInNlY3JldCI6IldSajZCTXVQNTQyTFpmWXdiTldlbTJLaCIsIkMiOiIwMzc5NWE0NGUwNGY1YWU5MGYyZGIwZTkzYzc3MzJkMDJkYTQ0ZGIxZmRkMWYzNDlkN2EwMzJmN2U5OGZkYzZjYzQiLCJpZCI6Im1SOVBKM016akwxeSJ9XX1dfQ
11 changes: 10 additions & 1 deletion moksha-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl TokenV3 {
}

pub fn deserialize(data: impl Into<String>) -> Result<Self, MokshaCoreError> {
let json = general_purpose::URL_SAFE.decode(
let json = general_purpose::URL_SAFE_NO_PAD.decode(
data.into()
.strip_prefix(TOKEN_PREFIX_V3)
.ok_or(MokshaCoreError::InvalidTokenPrefix)?
Expand Down Expand Up @@ -285,4 +285,13 @@ mod tests {
assert_eq!(tokens.tokens.len(), 1);
Ok(())
}

#[test]
fn test_tokens_deserialize_no_pad() -> anyhow::Result<()> {
let input = read_fixture("token_no_pad60.cashu")?;
let tokens = TokenV3::deserialize(input)?;
assert_eq!(tokens.memo, None);
assert_eq!(tokens.tokens.len(), 1);
Ok(())
}
}

0 comments on commit 1fca7d2

Please sign in to comment.