dmsc_jwt_manager_new

Function dmsc_jwt_manager_new 

Source
#[unsafe(no_mangle)]
pub extern "C" fn dmsc_jwt_manager_new( secret: *const c_char, expiry_secs: u64, ) -> *mut CDMSCJWTManager
Expand description

Creates a new CDMSCJWTManager instance with specified secret and expiration.

Initializes a JWT manager for token generation and validation. The manager uses HMAC-SHA256 (HS256) algorithm for signing tokens. The secret key must be kept confidential and should be at least 256 bits (32 bytes) for adequate security.

§Parameters

  • secret: Pointer to null-terminated C string containing the JWT signing secret. Must not be NULL. Empty strings are accepted but provide minimal security.
  • expiry_secs: Token expiration time in seconds from issuance. Tokens will be rejected as expired after this duration. Typical values range from 300 (5 minutes) for sensitive operations to 86400 (24 hours) for long-lived sessions.

§Returns

Pointer to newly allocated CDMSCJWTManager on success, or NULL if:

  • secret parameter is NULL
  • Memory allocation fails
  • Secret contains invalid UTF-8 sequences

§Security Considerations

The secret key should be:

  • Generated using cryptographically secure random number generator
  • Stored securely (environment variables, secrets manager)
  • Rotated periodically in production environments
  • Unique per environment (development, staging, production)

§Example

CDMSCJWTManager* jwt = dmsc_jwt_manager_new(
    "your-256-bit-secret-key-here",
    3600  // 1 hour expiration
);
if (jwt == NULL) {
    // Handle initialization failure
}