Skip to content

Commit

Permalink
base64: Handle deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira authored and piegamesde committed Sep 11, 2023
1 parent 12176a6 commit dd81aec
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use base64::Engine;

macro_rules! ensure {
($cond:expr, $err:expr $(,)?) => {
if !$cond {
Expand Down Expand Up @@ -121,15 +123,18 @@ pub fn hashcash(resource: String, bits: u32) -> String {
time::format_description::modifier::Day::default(),
)),
];

let base64_engine = base64::engine::general_purpose::STANDARD;

/* I'm pretty sure HashCash should work with any time zone */
let date = base64::encode(
let date = base64_engine.encode(
time::OffsetDateTime::now_utc()
.date()
.format(&format[..])
.unwrap(),
);

let rand: String = base64::encode(
let rand: String = base64_engine.encode(
rand::thread_rng()
.sample_iter(&Standard)
.take(16)
Expand All @@ -149,7 +154,7 @@ pub fn hashcash(resource: String, bits: u32) -> String {
date,
resource,
rand,
base64::encode(counter)
base64_engine.encode(counter)
);

hasher.update(&stamp);
Expand Down

0 comments on commit dd81aec

Please sign in to comment.