Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 220e434

Browse files
committed
feat: impl sqlx::Type for SerialNumber
1 parent f96da52 commit 220e434

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/database/serial_number.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bigdecimal::num_bigint::BigUint;
22
use rand::TryRngCore;
33
use sqlx::types::BigDecimal;
4-
use sqlx::{Decode, Encode};
4+
use sqlx::{Decode, Encode, Postgres, Type};
55

66
// TODO: This could be in polyproto instead
77

@@ -80,6 +80,11 @@ impl SerialNumber {
8080
fn normalize_first_byte(buf: &mut [u8; 20]) {
8181
buf[0] %= 128;
8282
}
83+
84+
/// Returns a reference to the inner [BigDecimal] field.
85+
pub fn as_bigdecimal(&self) -> &BigDecimal {
86+
&self.0
87+
}
8388
}
8489

8590
impl From<polyproto::types::x509_cert::SerialNumber> for SerialNumber {
@@ -94,6 +99,12 @@ impl From<SerialNumber> for polyproto::types::x509_cert::SerialNumber {
9499
}
95100
}
96101

102+
impl Type<Postgres> for SerialNumber {
103+
fn type_info() -> <Postgres as sqlx::Database>::TypeInfo {
104+
BigDecimal::type_info()
105+
}
106+
}
107+
97108
#[cfg(test)]
98109
#[allow(clippy::unwrap_used)]
99110
mod test {

0 commit comments

Comments
 (0)