File tree Expand file tree Collapse file tree 2 files changed +4
-11
lines changed
primitives/src/postgres/field Expand file tree Collapse file tree 2 files changed +4
-11
lines changed Original file line number Diff line number Diff line change 1
1
use std:: error:: Error ;
2
2
3
3
use crate :: ChannelId ;
4
+ use hex:: FromHex ;
4
5
use postgres_types:: { FromSql , Type } ;
5
6
6
7
#[ derive( Debug ) ]
@@ -16,16 +17,8 @@ impl<'a> FromSql<'a> for ChannelIdPg {
16
17
fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < ChannelIdPg , Box < dyn Error + Sync + Send > > {
17
18
let str_slice = <& str as FromSql >:: from_sql ( ty, raw) ?;
18
19
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) ?;
29
22
30
23
Ok ( ChannelIdPg ( id. into ( ) ) )
31
24
}
Original file line number Diff line number Diff line change 1
- use crate :: db :: field:: { BigNumPg , ChannelIdPg } ;
1
+ use primitives :: postgres :: field:: { BigNumPg , ChannelIdPg } ;
2
2
use crate :: db:: DbPool ;
3
3
use bb8_postgres:: tokio_postgres:: { types:: Json , Row } ;
4
4
use hyper:: { Body , Request } ;
You can’t perform that action at this time.
0 commit comments