Skip to main content

Crate genrs_lib

Crate genrs_lib 

Source
Expand description

§genrs Library

A versatile key and UUID generation library that allows you to:

  • Generate secure random keys of arbitrary length
  • Encode keys in either hexadecimal (Hex) or Base64 (Base64) format
  • Generate UUIDs of any version (V1, V3, V4, V5)

§Example usage

use genrs_lib::{encode_key, generate_key, generate_uuid, EncodingFormat, UuidVersion};

// Generate a random key
let key = generate_key(32);
let encoded_key = encode_key(key, EncodingFormat::Base64).unwrap();
println!("Generated and encoded key: {}", encoded_key);

// Generate a UUID V4
let uuid_v4 = generate_uuid(UuidVersion::V4, None, None).unwrap();
println!("Generated UUID V4: {}", uuid_v4);

§Features

  • Key Generation: Uses a cryptographically secure random number generator (CSPRNG) to generate random keys of arbitrary length.
  • Key Encoding: Supports Hex and Base64 encoding formats for ease of transmission and storage.
  • UUID Generation: Create universally unique identifiers (UUIDs) for V1 (timestamp-based), V3 (namespace + name, MD5), V4 (random), and V5 (namespace + name, SHA-1).

§Referenced Libraries

  • rand for secure random number generation.
  • uuid for UUID generation.
  • hex for encoding keys in hexadecimal format.
  • base64 for encoding keys in Base64 format.

Enums§

EncodingFormat
Enum to represent the encoding format for the key.
UuidVersion
Enum to represent UUID versions.

Functions§

encode_key
Encodes the given key into the specified format (Hex or Base64).
generate_key
Generates a random key of the given length in bytes.
generate_uuid
Generates a UUID of the specified version.