dmsc/java/classes/
auth.rs

1//! Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
2//!
3//! This file is part of DMSC.
4//! The DMSC project belongs to the Dunimd Team.
5//!
6//! Licensed under the Apache License, Version 2.0 (the "License");
7//! You may not use this file except in compliance with the License.
8//! You may obtain a copy of the License at
9//!
10//!     http://www.apache.org/licenses/LICENSE-2.0
11//!
12//! Unless required by applicable law or agreed to in writing, software
13//! distributed under the License is distributed on an "AS IS" BASIS,
14//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15//! See the License for the specific language governing permissions and
16//! limitations under the License.
17
18//! # Auth Module JNI Bindings
19//!
20//! JNI bindings for DMSC auth classes.
21
22use jni::JNIEnv;
23use jni::objects::{JClass, JString};
24use jni::sys::{jlong, jstring};
25use crate::auth::{DMSCAuthModule, DMSCAuthConfig};
26use crate::java::exception::check_not_null;
27
28#[no_mangle]
29pub extern "system" fn Java_com_dunimd_dmsc_auth_DMSCAuthModule_new0(
30    mut env: JNIEnv,
31    _class: JClass,
32    config_ptr: jlong,
33) -> jlong {
34    if !check_not_null(&mut env, config_ptr, "DMSCAuthConfig") {
35        return 0;
36    }
37    0
38}
39
40#[no_mangle]
41pub extern "system" fn Java_com_dunimd_dmsc_auth_DMSCAuthModule_free0(
42    _env: JNIEnv,
43    _class: JClass,
44    ptr: jlong,
45) {
46    if ptr != 0 {
47        unsafe {
48            let _ = Box::from_raw(ptr as *mut DMSCAuthModule);
49        }
50    }
51}
52
53#[no_mangle]
54pub extern "system" fn Java_com_dunimd_dmsc_auth_DMSCAuthConfig_new0(
55    _env: JNIEnv,
56    _class: JClass,
57) -> jlong {
58    let config = Box::new(DMSCAuthConfig::default());
59    Box::into_raw(config) as jlong
60}
61
62#[no_mangle]
63pub extern "system" fn Java_com_dunimd_dmsc_auth_DMSCAuthConfig_free0(
64    _env: JNIEnv,
65    _class: JClass,
66    ptr: jlong,
67) {
68    if ptr != 0 {
69        unsafe {
70            let _ = Box::from_raw(ptr as *mut DMSCAuthConfig);
71        }
72    }
73}
74
75#[no_mangle]
76pub extern "system" fn Java_com_dunimd_dmsc_auth_DMSCJWTManager_generateToken(
77    mut env: JNIEnv,
78    _class: JClass,
79    ptr: jlong,
80    _claims_ptr: jlong,
81) -> jstring {
82    if !check_not_null(&mut env, ptr, "DMSCJWTManager") {
83        return std::ptr::null_mut();
84    }
85    std::ptr::null_mut()
86}
87
88#[no_mangle]
89pub extern "system" fn Java_com_dunimd_dmsc_auth_DMSCJWTManager_validateToken(
90    mut env: JNIEnv,
91    _class: JClass,
92    ptr: jlong,
93    _token: JString,
94) -> jlong {
95    if !check_not_null(&mut env, ptr, "DMSCJWTManager") {
96        return 0;
97    }
98    0
99}