scram_rs/c_api/
mod.rs

1/*-
2 * Scram-rs - a SCRAM authentification authorization library
3 * 
4 * Copyright (C) 2021  Aleksandr Morozov
5 * Copyright (C) 2025 Aleksandr Morozov
6 * 
7 * The syslog-rs crate can be redistributed and/or modified
8 * under the terms of either of the following licenses:
9 *
10 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
11 *
12 *   2. The MIT License (MIT)
13 *                     
14 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
15 */
16/*!
17 * 
18 * In order to use the C_API, the scramrs.h file should be included in the C-file.
19 * 
20 * A static library should be attached and compiled for example:
21 * gcc test1.c ../../target/debug/libscram_rs.a -o test1
22 * 
23 * Follow guides for each data types and methods in the comments in the h-file. 
24 * There are notices which return types should be deallocated using which functions.
25 * 
26 * Do not attempt to free memeory using malloc.h free().
27 * 
28 * */
29
30
31use core::mem;
32
33#[cfg(not(feature = "std"))]
34use alloc::boxed::Box;
35
36
37pub(super) mod error;
38pub(super) mod client;
39pub(super) mod nonce;
40pub(super) mod common;
41pub(super) mod server;
42pub(super) mod password;
43pub(super) mod key;
44pub(super) mod export;
45
46#[cfg(all(not(feature = "without_capi"), not(feature = "std")))]
47pub(super) mod allocator;
48
49//pub(super) mod providers;
50
51#[repr(C)]
52pub enum CApiScramHasherProvider
53{
54    RustNative = 0,
55    RustRing = 1,
56}
57
58impl CApiScramHasherProvider
59{
60    pub 
61    fn validate(&self) -> bool
62    {
63        if mem::discriminant(self) == mem::discriminant(&CApiScramHasherProvider::RustNative)
64        {
65            return true
66        }
67        else if mem::discriminant(self) == mem::discriminant(&CApiScramHasherProvider::RustRing)
68        {
69            return true
70        }
71        else 
72        {
73            return false;    
74        }
75    }
76}
77
78#[repr(C)]
79pub enum CApiScramTypeAlias
80{
81    Sha1 = 0,
82    Sha256 = 1,
83    Sha512 = 3,
84}
85
86#[repr(C)]
87pub enum CApiScramRes
88{
89    Ok = 0,
90    Err = 1,
91    NullPtr = 2,
92}
93
94#[inline]
95pub 
96fn into_boxed_ptr<T>(item: T) -> *mut T
97{
98    return Box::into_raw(Box::new(item));
99}