-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move ffi type container to boring-additions
* Use boring::derive for EC and ED instead of own implementation
- Loading branch information
Jan Rüth
committed
Nov 24, 2023
1 parent
319029f
commit aa74b45
Showing
15 changed files
with
417 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::{ | ||
ops::{Deref, DerefMut}, | ||
ptr::NonNull, | ||
}; | ||
|
||
use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; | ||
|
||
pub struct EvpAeadCtxRef(Opaque); | ||
|
||
unsafe impl ForeignTypeRef for EvpAeadCtxRef { | ||
type CType = boring_sys::EVP_AEAD_CTX; | ||
} | ||
|
||
unsafe impl Sync for EvpAeadCtxRef {} | ||
unsafe impl Send for EvpAeadCtxRef {} | ||
|
||
pub struct EvpAeadCtx(NonNull<boring_sys::EVP_AEAD_CTX>); | ||
|
||
unsafe impl Sync for EvpAeadCtx {} | ||
unsafe impl Send for EvpAeadCtx {} | ||
|
||
unsafe impl ForeignType for EvpAeadCtx { | ||
type CType = boring_sys::EVP_AEAD_CTX; | ||
|
||
type Ref = EvpAeadCtxRef; | ||
|
||
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self { | ||
Self(NonNull::new_unchecked(ptr)) | ||
} | ||
|
||
fn as_ptr(&self) -> *mut Self::CType { | ||
self.0.as_ptr() | ||
} | ||
} | ||
|
||
impl Drop for EvpAeadCtx { | ||
fn drop(&mut self) { | ||
unsafe { | ||
boring_sys::EVP_AEAD_CTX_free(self.0.as_ptr()); | ||
} | ||
} | ||
} | ||
|
||
impl Deref for EvpAeadCtx { | ||
type Target = EvpAeadCtxRef; | ||
|
||
fn deref(&self) -> &EvpAeadCtxRef { | ||
unsafe { EvpAeadCtxRef::from_ptr(self.as_ptr()) } | ||
} | ||
} | ||
|
||
impl DerefMut for EvpAeadCtx { | ||
fn deref_mut(&mut self) -> &mut EvpAeadCtxRef { | ||
unsafe { EvpAeadCtxRef::from_ptr_mut(self.as_ptr()) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod types; | ||
|
||
pub use types::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::{ | ||
ops::{Deref, DerefMut}, | ||
ptr::NonNull, | ||
}; | ||
|
||
use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; | ||
|
||
pub struct EvpPkeyCtxRef(Opaque); | ||
|
||
unsafe impl ForeignTypeRef for EvpPkeyCtxRef { | ||
type CType = boring_sys::EVP_PKEY_CTX; | ||
} | ||
|
||
unsafe impl Sync for EvpPkeyCtxRef {} | ||
unsafe impl Send for EvpPkeyCtxRef {} | ||
|
||
unsafe impl Sync for EvpPkeyCtx {} | ||
unsafe impl Send for EvpPkeyCtx {} | ||
|
||
pub struct EvpPkeyCtx(NonNull<boring_sys::EVP_PKEY_CTX>); | ||
unsafe impl ForeignType for EvpPkeyCtx { | ||
type CType = boring_sys::EVP_PKEY_CTX; | ||
|
||
type Ref = EvpPkeyCtxRef; | ||
|
||
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self { | ||
Self(NonNull::new_unchecked(ptr)) | ||
} | ||
|
||
fn as_ptr(&self) -> *mut Self::CType { | ||
self.0.as_ptr() | ||
} | ||
} | ||
impl Drop for EvpPkeyCtx { | ||
fn drop(&mut self) { | ||
unsafe { | ||
boring_sys::EVP_PKEY_CTX_free(self.0.as_ptr()); | ||
} | ||
} | ||
} | ||
|
||
impl core::fmt::Debug for EvpPkeyCtx { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_tuple("EvpPkeyCtx").field(&self.0).finish() | ||
} | ||
} | ||
|
||
impl Deref for EvpPkeyCtx { | ||
type Target = EvpPkeyCtxRef; | ||
|
||
fn deref(&self) -> &EvpPkeyCtxRef { | ||
unsafe { EvpPkeyCtxRef::from_ptr(self.as_ptr()) } | ||
} | ||
} | ||
|
||
impl DerefMut for EvpPkeyCtx { | ||
fn deref_mut(&mut self) -> &mut EvpPkeyCtxRef { | ||
unsafe { EvpPkeyCtxRef::from_ptr_mut(self.as_ptr()) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod types; | ||
|
||
pub use types::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{ | ||
ops::{Deref, DerefMut}, | ||
ptr::NonNull, | ||
}; | ||
|
||
use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; | ||
|
||
use crate::helper::{cvt, cvt_p}; | ||
|
||
pub struct HmacCtxRef(Opaque); | ||
|
||
unsafe impl ForeignTypeRef for HmacCtxRef { | ||
type CType = boring_sys::HMAC_CTX; | ||
} | ||
|
||
unsafe impl Sync for HmacCtxRef {} | ||
unsafe impl Send for HmacCtxRef {} | ||
|
||
pub struct HmacCtx(NonNull<boring_sys::HMAC_CTX>); | ||
|
||
unsafe impl Sync for HmacCtx {} | ||
unsafe impl Send for HmacCtx {} | ||
|
||
unsafe impl ForeignType for HmacCtx { | ||
type CType = boring_sys::HMAC_CTX; | ||
|
||
type Ref = HmacCtxRef; | ||
|
||
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self { | ||
Self(NonNull::new_unchecked(ptr)) | ||
} | ||
|
||
fn as_ptr(&self) -> *mut Self::CType { | ||
self.0.as_ptr() | ||
} | ||
} | ||
|
||
impl Clone for HmacCtx { | ||
fn clone(&self) -> Self { | ||
unsafe { | ||
let ctx = HmacCtx::from_ptr(cvt_p(boring_sys::HMAC_CTX_new()).unwrap()); | ||
|
||
cvt(boring_sys::HMAC_CTX_copy(ctx.as_ptr(), self.0.as_ptr())).unwrap(); | ||
ctx | ||
} | ||
} | ||
} | ||
|
||
impl Drop for HmacCtx { | ||
fn drop(&mut self) { | ||
unsafe { | ||
boring_sys::HMAC_CTX_free(self.0.as_ptr()); | ||
} | ||
} | ||
} | ||
|
||
impl Deref for HmacCtx { | ||
type Target = HmacCtxRef; | ||
|
||
fn deref(&self) -> &HmacCtxRef { | ||
unsafe { Self::Target::from_ptr(self.as_ptr()) } | ||
} | ||
} | ||
|
||
impl DerefMut for HmacCtx { | ||
fn deref_mut(&mut self) -> &mut HmacCtxRef { | ||
unsafe { HmacCtxRef::from_ptr_mut(self.as_ptr()) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod aead; | ||
pub mod evp; | ||
pub(crate) mod helper; | ||
pub mod hmac; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.