Skip to content

Commit 746d85b

Browse files
authored
Merge pull request #3 from tmthecoder/add-repr-c
Add `#[repr(C)]` as a feature
2 parents 22b94f3 + 8bd7fd6 commit 746d85b

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ authors = ["Tejas Mehta <[email protected]>"]
1010
version = "0.2.0"
1111
edition = "2021"
1212

13+
[features]
14+
default = []
15+
ffi = []
16+
1317
[dependencies]
1418
hmac = "0.12.0"
1519
sha-1 = "0.10.0"

src/hotp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::util::{base32_decode, get_code, hash_generic, MacDigest};
1616
/// [RFC4226]: https://datatracker.ietf.org/doc/html/rfc4226
1717
1818
#[derive(Debug, Clone, Hash)]
19+
#[cfg_attr(feature = "ffi", repr(C))]
1920
pub struct HOTP {
2021
/// The secret key used in the HMAC process.
2122
///

src/totp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::util::{base32_decode, get_code, hash_generic, MacDigest};
1515
///
1616
/// [RFC6238]: https://datatracker.ietf.org/doc/html/rfc6238
1717
#[derive(Debug, Clone, Hash)]
18+
#[cfg_attr(feature = "ffi", repr(C))]
1819
pub struct TOTP {
1920
/// The secret key used in the HMAC process.
2021
///

src/util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use crate::totp::TOTP;
1919
/// may not support other digest algorithms.
2020
///
2121
/// [RFC6238]: https://datatracker.ietf.org/doc/html/rfc6238
22+
2223
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
24+
#[cfg_attr(feature = "ffi", repr(C))]
2325
pub enum MacDigest {
2426
SHA1,
2527
SHA256,
@@ -77,13 +79,15 @@ pub(crate) fn base32_decode(data: &str) -> Option<Vec<u8>> {
7779
///
7880
/// It's either a TOTP or a HOTP with its current counter.
7981
#[derive(Debug)]
82+
#[cfg_attr(feature = "ffi", repr(C))]
8083
pub enum ParseResult {
8184
TOTP(TOTP),
8285
HOTP(HOTP, u64),
8386
}
8487

8588
/// Different error types of the optauth URI parsing.
8689
#[derive(Debug)]
90+
#[cfg_attr(feature = "ffi", repr(C))]
8791
pub enum ParseError {
8892
UriParseError(url::ParseError),
8993
WrongScheme(String),

0 commit comments

Comments
 (0)