Skip to content

Commit

Permalink
feat: bind gen_key() & gen_nonce()
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGw committed May 31, 2024
1 parent c64b017 commit 597db6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/gcm_rs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from gcm_rs import *

print(sum_as_string(4,4))
print(gen_key())
14 changes: 11 additions & 3 deletions rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ pub mod gcm;
pub mod random;
pub mod types;

use random::{gen_key as gk, gen_nonce as gn};

use pyo3::prelude::*;

#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
fn gen_nonce() -> PyResult<Vec<u8>> {
Ok(gn())
}

#[pyfunction]
fn gen_key() -> PyResult<Vec<u8>> {
Ok(gk())
}

#[pymodule]
#[pyo3(name = "_lib_name")]
fn pyrust(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
m.add_function(wrap_pyfunction!(gen_nonce, m)?)?;
m.add_function(wrap_pyfunction!(gen_key, m)?)?;
Ok(())
}

0 comments on commit 597db6c

Please sign in to comment.