/*-
 * Scram-rs - a SCRAM authentification authorization library
 * 
 * Copyright (C) 2021  Aleksandr Morozov
 * Copyright (C) 2025 Aleksandr Morozov
 * 
 * The syslog-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *
 *   2. The MIT License (MIT)
 *                     
 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
 */
/*!
 * 
 * In order to use the C_API, the scramrs.h file should be included in the C-file.
 * 
 * A static library should be attached and compiled for example:
 * gcc test1.c ../../target/debug/libscram_rs.a -o test1
 * 
 * Follow guides for each data types and methods in the comments in the h-file. 
 * There are notices which return types should be deallocated using which functions.
 * 
 * Do not attempt to free memeory using malloc.h free().
 * 
 * */


use core::mem;

#[cfg(not(feature = "std"))]
use alloc::boxed::Box;


pub(super) mod error;
pub(super) mod client;
pub(super) mod nonce;
pub(super) mod common;
pub(super) mod server;
pub(super) mod password;
pub(super) mod key;
pub(super) mod export;

#[cfg(all(not(feature = "without_capi"), not(feature = "std")))]
pub(super) mod allocator;

//pub(super) mod providers;

#[repr(C)]
pub enum CApiScramHasherProvider
{
    RustNative = 0,
    RustRing = 1,
}

impl CApiScramHasherProvider
{
    pub 
    fn validate(&self) -> bool
    {
        if mem::discriminant(self) == mem::discriminant(&CApiScramHasherProvider::RustNative)
        {
            return true
        }
        else if mem::discriminant(self) == mem::discriminant(&CApiScramHasherProvider::RustRing)
        {
            return true
        }
        else 
        {
            return false;    
        }
    }
}

#[repr(C)]
pub enum CApiScramTypeAlias
{
    Sha1 = 0,
    Sha256 = 1,
    Sha512 = 2,
    Sha3_512 = 3,
}

#[repr(C)]
pub enum CApiScramRes
{
    Ok = 0,
    Err = 1,
    NullPtr = 2,
}

#[inline]
pub 
fn into_boxed_ptr<T>(item: T) -> *mut T
{
    return Box::into_raw(Box::new(item));
}
