Skip to content

Commit

Permalink
flag finish
Browse files Browse the repository at this point in the history
  • Loading branch information
PootisHunter committed Jul 10, 2024
1 parent eee654a commit 06f93e3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use serde::{Deserialize, Serialize};
use std::fs;
use std::error::Error;
use uuid::Uuid;

#[derive(Deserialize)]
struct CourseConfiguration {
Expand All @@ -13,7 +10,13 @@ struct CourseConfiguration {
}

impl CourseConfiguration {
pub fn new(course_identifier: CourseIdentifier, weeks: Vec<Weeks>, tasks: Vec<WeeksTasks>, taskbuild: Vec<WeeksTasksBuild>, taskoutput: Vec<WeeksTasksOutput>) -> CourseConfiguration {
pub fn new(
course_identifier: CourseIdentifier,
weeks: Vec<Weeks>,
tasks: Vec<WeeksTasks>,
taskbuild: Vec<WeeksTasksBuild>,
taskoutput: Vec<WeeksTasksOutput>,
) -> CourseConfiguration {
CourseConfiguration {
course_identifier,
weeks,
Expand All @@ -34,7 +37,12 @@ struct CourseIdentifier {
}

impl CourseIdentifier {
pub fn new(identifier: String, name: String, description: String, version: String) -> CourseIdentifier {
pub fn new(
identifier: String,
name: String,
description: String,
version: String,
) -> CourseIdentifier {
CourseIdentifier {
identifier,
name,
Expand All @@ -51,10 +59,7 @@ struct Weeks {

impl Weeks {
pub fn new(number: i32, theme: String) -> Weeks {
Weeks {
number,
theme,
}
Weeks { number, theme }
}
}
#[derive(Deserialize)]
Expand All @@ -63,12 +68,19 @@ struct WeeksTasks {
name: String,
description: String,
points: f32,
flags: Vec<Flag>,
flags: Vec<FlagConfig>,
subtasks: Vec<SubTask>,
}

impl WeeksTasks {
pub fn new(id: String, name: String, description: String, points: f32, flags: Vec<Flag>, subtasks: Vec<SubTask>) -> WeeksTasks {
pub fn new(
id: String,
name: String,
description: String,
points: f32,
flags: Vec<FlagConfig>,
subtasks: Vec<SubTask>,
) -> WeeksTasks {
WeeksTasks {
id,
name,
Expand All @@ -80,17 +92,14 @@ impl WeeksTasks {
}
}
#[derive(Deserialize)]
struct Flag {
struct FlagConfig {
flag_type: String,
id: String,
}

impl Flag {
pub fn new(flag_type: String, id: String) -> Flag {
Flag {
flag_type,
id,
}
impl FlagConfig {
pub fn new(flag_type: String, id: String) -> FlagConfig {
FlagConfig { flag_type, id }
}
}

Expand Down Expand Up @@ -136,9 +145,6 @@ struct WeeksTasksOutput {

impl WeeksTasksOutput {
pub fn new(name: String, output_type: String) -> WeeksTasksOutput {
WeeksTasksOutput {
name,
output_type,
}
WeeksTasksOutput { name, output_type }
}
}
21 changes: 21 additions & 0 deletions src/flag_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,31 @@ use uuid::Uuid;

type Hmac256 = Hmac<Sha3_256>;

/// Type for all possible algorithms to use when generating flag
///
///
/// #### Algorithms
/// - `HmacSha3_256` generates a HMAC using SHA3_256 hashing.
#[derive(PartialEq)]
pub enum Algorithm {
HmacSha3_256,
}

/// Flag type used to generate flag for specific purpose
///
/// Flags are 32 long hexstring and all flags need a flag prefix to be used
///
/// #### Flags
/// - `RngFlag` generates a random hexstring flag with given lenght and prefix
/// - `UserSeedFlag` generates a random hexstring flag with given user id (UUID) and prefix
/// - `UserDerivedFlag` generates a random hexstring flag with prefix, algorithm, secret, taskid
/// and Uuid
///
/// #### Functions
///
/// - `random_flag()` - `RngFlag` generator
/// - `user_seed_flag()` - `UserSeedFlag` generator
/// - `user_flag()` - `UserDerivedFlag` generator
pub enum Flag {
RngFlag(FlagUnit),
UserSeedFlag(FlagUnit),
Expand Down Expand Up @@ -133,6 +153,7 @@ fn user_derived_flag(
}
}
// not used might be used later
#[allow(dead_code)]
fn compare_hmac(
hmac: String,
uuid: Uuid,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod flag_generator;
pub mod config;

0 comments on commit 06f93e3

Please sign in to comment.