Skip to content

Commit

Permalink
flag finalizing
Browse files Browse the repository at this point in the history
  • Loading branch information
PootisHunter committed Jul 8, 2024
1 parent 838114c commit 586ffc9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/flag_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use uuid::Uuid;
type Hmac256 = Hmac<Sha3_256>;

#[derive(PartialEq)]
enum Algorithm {
pub enum Algorithm {
HmacSha3_256,
}

enum Flag {
pub enum Flag {
RngFlag(FlagUnit),
UserSeedFlag(FlagUnit),
UserDerivedFlag(FlagUnit),
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Flag {

#[allow(dead_code)]
#[derive(Debug)]
pub struct FlagUnit {
struct FlagUnit {
prefix: String,
suffix: String,
}
Expand Down Expand Up @@ -118,18 +118,18 @@ fn user_derived_flag(
secret: String,
taskid: String,
) -> Result<String, InvalidLength> {
if algorithm == Algorithm::HmacSha3_256 {
let input = format!("{}-{}", secret, uuid.as_hyphenated());
let slice = input.as_bytes();
let mut mac = Hmac256::new_from_slice(slice)?;
mac.update(taskid.as_bytes());

let result = mac.finalize();
let bytes = result.into_bytes();
let s = format!("{:x}", bytes);
return Ok(s);
} else {
panic!("Algorithm not supported")
match algorithm {
Algorithm::HmacSha3_256 => {
let input = format!("{}-{}", secret, uuid.as_hyphenated());
let slice = input.as_bytes();
let mut mac = Hmac256::new_from_slice(slice)?;
mac.update(taskid.as_bytes());

let result = mac.finalize();
let bytes = result.into_bytes();
let s = format!("{:x}", bytes);
return Ok(s);
}
}
}
// not used might be used later
Expand Down

0 comments on commit 586ffc9

Please sign in to comment.