Skip to content

Commit

Permalink
Switch to data-encoding for base64
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Aug 14, 2024
1 parent d04b592 commit 2c6043d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ rust-version = "1.70"

[dependencies]
anyhow = "1.0"
base64 = "0.22"
byteorder = "1.3"
clap = "4.0,<4.5" # For rust 1.70 compatibility
data-encoding = "2.0"
env_logger = "0.10"
flate2 = "1.0"
form_urlencoded = "1.1"
Expand Down
6 changes: 3 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::io::Write;
use std::sync::Arc;
use std::time::Duration;

use base64::prelude::*;
use data_encoding::BASE64;
use http_body_util::Full;
use hyper::body::{Bytes, Incoming};
use hyper::header::CONTENT_TYPE;
Expand Down Expand Up @@ -116,8 +116,8 @@ async fn api_router(request: Request<Incoming>, api: Arc<ApiInterface>)
let key_x = key_g.to_biguint().unwrap().modpow(key_k, key_n);
let bytes_n = key_n.to_bytes_be();
let bytes_x = key_x.to_bytes_be();
let _ = writeln!(lines, "Server.{stype}.N \"{}\"", BASE64_STANDARD.encode(bytes_n));
let _ = writeln!(lines, "Server.{stype}.X \"{}\"", BASE64_STANDARD.encode(bytes_x));
let _ = writeln!(lines, "Server.{stype}.N \"{}\"", BASE64.encode(&bytes_n));
let _ = writeln!(lines, "Server.{stype}.X \"{}\"", BASE64.encode(&bytes_x));
}
Response::builder().body(Full::from(lines)).unwrap()
}
Expand Down
14 changes: 7 additions & 7 deletions src/bin/moulars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::ExitCode;

use base64::prelude::*;
use data_encoding::BASE64;
use clap::{Command, Arg};
use log::error;
use num_bigint::{BigUint, ToBigUint};
Expand Down Expand Up @@ -83,8 +83,8 @@ fn main() -> ExitCode {
let key_x = key_g.to_biguint().unwrap().modpow(key_k, key_n);
let bytes_n = key_n.to_bytes_be();
let bytes_x = key_x.to_bytes_be();
println!("Server.{stype}.N \"{}\"", BASE64_STANDARD.encode(bytes_n));
println!("Server.{stype}.X \"{}\"", BASE64_STANDARD.encode(bytes_x));
println!("Server.{stype}.N \"{}\"", BASE64.encode(&bytes_n));
println!("Server.{stype}.X \"{}\"", BASE64.encode(&bytes_x));
}

return ExitCode::SUCCESS;
Expand Down Expand Up @@ -195,10 +195,10 @@ fn generate_keys() {

let stype_lower = stype.to_ascii_lowercase();
return (
format!("{stype_lower}.n = \"{}\"", BASE64_STANDARD.encode(&bytes_n)),
format!("{stype_lower}.k = \"{}\"", BASE64_STANDARD.encode(&bytes_k)),
format!("Server.{stype}.N \"{}\"", BASE64_STANDARD.encode(&bytes_n)),
format!("Server.{stype}.X \"{}\"", BASE64_STANDARD.encode(&bytes_x)),
format!("{stype_lower}.n = \"{}\"", BASE64.encode(&bytes_n)),
format!("{stype_lower}.k = \"{}\"", BASE64.encode(&bytes_k)),
format!("Server.{stype}.N \"{}\"", BASE64.encode(&bytes_n)),
format!("Server.{stype}.X \"{}\"", BASE64.encode(&bytes_x)),
);
}
}));
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::path::{Path, PathBuf};
use std::sync::OnceLock;

use anyhow::{anyhow, Context, Result};
use base64::prelude::*;
use data_encoding::BASE64;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use num_bigint::BigUint;
use rand::Rng;
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct ServerConfig {
}

fn decode_crypt_key(value: &str) -> Result<BigUint> {
let bytes = BASE64_STANDARD.decode(value)
let bytes = BASE64.decode(value.as_bytes())
.with_context(|| format!("Could not parse Base64 key '{value}'"))?;
if bytes.len() == 64 {
Ok(BigUint::from_bytes_be(&bytes))
Expand Down

0 comments on commit 2c6043d

Please sign in to comment.