Skip to content

Commit

Permalink
Update docs - part1
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Feb 11, 2024
1 parent f2e8913 commit a0940b9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn get_binary() -> String {
path::Path::new(&binary).file_name().unwrap().to_str().unwrap().to_string()
}

/// Struct to store the cargo information
#[derive(Debug)]
pub struct Cargo {
pub binary: String,
Expand All @@ -30,10 +31,12 @@ pub struct Cargo {
pub pkg_version_pre: String,
}

/// Uses compile time macros to load Cargo metadata via environment variables during compilation process
///
/// ## References
/// - https://doc.rust-lang.org/cargo/reference/environment-variables.html
/// - https://github.com/rust-lang/cargo/issues/8251#issuecomment-631731144
/// - https://github.com/rust-lang/cargo/issues/11966#issue-1664748892
/// - [Official Docs](https://doc.rust-lang.org/cargo/reference/environment-variables.html)
/// - [GitHub Issues](https://github.com/rust-lang/cargo/issues/8251#issuecomment-631731144)
/// - [GitHub Issues](https://github.com/rust-lang/cargo/issues/11966#issue-1664748892)
pub fn build_info() -> Cargo {
let cargo = Cargo {
binary: get_binary(),
Expand All @@ -57,10 +60,7 @@ lazy_static! {
pub static ref FERNET: Fernet = Fernet::new(&generate_key()).unwrap();
}

/// Create a Fernet object to encrypt and decrypt session token.
///
/// ## References:
/// https://docs.rs/fernet/latest/fernet/
/// Create a [Fernet](https://docs.rs/fernet/latest/fernet/) object to encrypt and decrypt session token.
fn generate_key() -> String {
Fernet::generate_key()
}
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ mod template;
mod constant;
mod routes;

/// Contains entrypoint and initializer settings to trigger the asynchronous HTTPServer
///
/// # Example
/// ```no_run
/// #[actix_rt::main]
/// async fn main() {
/// rustream::start().await.unwrap();
/// }
/// ```
pub async fn start() -> io::Result<()> {
let cargo = constant::build_info();
let args = squire::parser::arguments();
Expand Down
12 changes: 6 additions & 6 deletions src/squire/secure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use sha2::{Digest, Sha512};

/// Generates hash value for the given payload using sha512 algorithm
///
/// References:
/// https://docs.rs/sha2/latest/sha2/#usage
/// ## References:
/// - [Official docs](https://docs.rs/sha2/latest/sha2/#usage)
pub fn calculate_hash(value: String) -> String {
let mut hasher = Sha512::new();
hasher.update(value);
Expand All @@ -20,17 +20,17 @@ pub fn calculate_hash(value: String) -> String {
///
/// (i.e., a string in which each character in the string is treated as a byte of binary data)
///
/// References:
/// https://docs.rs/base64/latest/base64/#url-safe-alphabet
/// ## References:
/// - [Official docs](https://docs.rs/base64/latest/base64/#url-safe-alphabet)
#[allow(dead_code)] // Just for reference
pub fn base64_encode(value: &str) -> String {
URL_SAFE.encode(value.as_bytes())
}

/// Decode a string of data which has been encoded using base64 (similar to the built-in atob function in native JS)
///
/// References:
/// https://docs.rs/base64/latest/base64/#url-safe-alphabet
/// ## References:
/// - [Official Docs](https://docs.rs/base64/latest/base64/#url-safe-alphabet)
pub fn base64_decode(value: &str) -> Result<String, &'static str> {
if let Ok(decoded_bytes) = URL_SAFE.decode(value) {
if let Ok(decoded_str) = String::from_utf8(decoded_bytes) {
Expand Down
15 changes: 11 additions & 4 deletions src/template.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
/// Create static objects that can be tossed around the modules
///
/// References:
/// https://doc.rust-lang.org/std/macro.include_str.html
/// Index page template that is served as HTML response for the root endpoint.
pub static INDEX: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/index.html"));

/// Landing page template that is served as HTML response while streaming videos.
pub static LANDING: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/land.html"));

/// Listing page template that is served as HTML response after successful authentication.
pub static LISTING: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/list.html"));

/// Logout page template that is served as HTML response when the user decides to end the session.
pub static LOGOUT: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/logout.html"));

/// Session page template that is served as HTML response when invalid/expired session tokens are received.
pub static SESSION: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/session.html"));

/// Unauthorized page template that is served as HTML response after failed authentication.
pub static UNAUTHORIZED: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/unauthorized.html"));

0 comments on commit a0940b9

Please sign in to comment.