Skip to content

Commit b16b797

Browse files
committed
small fixes
1 parent d9d3ad7 commit b16b797

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

primitives/src/postgres/field/channel_id.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::error::Error;
22

33
use crate::ChannelId;
4+
use hex::FromHex;
45
use postgres_types::{FromSql, Type};
56

67
#[derive(Debug)]
@@ -16,16 +17,8 @@ impl<'a> FromSql<'a> for ChannelIdPg {
1617
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<ChannelIdPg, Box<dyn Error + Sync + Send>> {
1718
let str_slice = <&str as FromSql>::from_sql(ty, raw)?;
1819

19-
// @TODO: Add this check back!
20-
// if result.len() != 32 {
21-
// return Err(DomainError::InvalidArgument(format!(
22-
// "Invalid validator id value {}",
23-
// value
24-
// )));
25-
// }
26-
27-
let mut id: [u8; 32] = [0; 32];
28-
id.copy_from_slice(&hex::decode(str_slice)?);
20+
// FromHex::from_hex for fixed-sized arrays will guard against the length of the string!
21+
let id: [u8; 32] = <[u8; 32] as FromHex>::from_hex(str_slice)?;
2922

3023
Ok(ChannelIdPg(id.into()))
3124
}

sentry/src/middleware/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::db::field::{BigNumPg, ChannelIdPg};
1+
use primitives::postgres::field::{BigNumPg, ChannelIdPg};
22
use crate::db::DbPool;
33
use bb8_postgres::tokio_postgres::{types::Json, Row};
44
use hyper::{Body, Request};

0 commit comments

Comments
 (0)