@@ -7,7 +7,7 @@ use p256::{NonZeroScalar, SecretKey};
77use rand:: rngs:: OsRng ;
88use rand:: RngCore ;
99use serde:: Serialize ;
10- use serde_bytes:: ByteBuf ;
10+ use serde_bytes:: ByteArray ;
1111use serde_indexed:: SerializeIndexed ;
1212use tokio:: time:: sleep;
1313use tracing:: { debug, error, instrument, trace} ;
@@ -49,9 +49,9 @@ impl Serialize for QrCodeOperationHint {
4949#[ derive( Debug , SerializeIndexed ) ]
5050pub struct CableQrCode {
5151 // Key 0: a 33-byte, P-256, X9.62, compressed public key.
52- pub public_key : ByteBuf ,
52+ pub public_key : ByteArray < 33 > ,
5353 // Key 1: a 16-byte random QR secret.
54- pub qr_secret : ByteBuf ,
54+ pub qr_secret : ByteArray < 16 > ,
5555 /// Key 2: the number of assigned tunnel server domains known to this implementation.
5656 pub known_tunnel_domains_count : u8 ,
5757 /// Key 3: (optional) the current time in epoch seconds.
@@ -144,7 +144,13 @@ impl<'d> CableQrCodeDevice<'d> {
144144 ) -> Self {
145145 let private_key_scalar = NonZeroScalar :: random ( & mut OsRng ) ;
146146 let private_key = SecretKey :: from_bytes ( & private_key_scalar. to_bytes ( ) ) . unwrap ( ) ;
147- let public_key = private_key. public_key ( ) . as_affine ( ) . to_encoded_point ( true ) ;
147+ let public_key: [ u8 ; 33 ] = private_key
148+ . public_key ( )
149+ . as_affine ( )
150+ . to_encoded_point ( true )
151+ . as_bytes ( )
152+ . try_into ( )
153+ . unwrap ( ) ;
148154 let mut qr_secret = [ 0u8 ; 16 ] ;
149155 OsRng :: default ( ) . fill_bytes ( & mut qr_secret) ;
150156
@@ -155,8 +161,8 @@ impl<'d> CableQrCodeDevice<'d> {
155161
156162 Self {
157163 qr_code : CableQrCode {
158- public_key : ByteBuf :: from ( public_key. as_bytes ( ) ) ,
159- qr_secret : ByteBuf :: from ( qr_secret) ,
164+ public_key : ByteArray :: from ( public_key) ,
165+ qr_secret : ByteArray :: from ( qr_secret) ,
160166 known_tunnel_domains_count : KNOWN_TUNNEL_DOMAINS . len ( ) as u8 ,
161167 current_time : current_unix_time,
162168 operation_hint : hint,
@@ -251,11 +257,11 @@ impl<'d> Device<'d, Cable, CableChannel<'d>> for CableQrCodeDevice<'_> {
251257 let routing_id_str = hex:: encode ( & advert. routing_id ) ;
252258 let _nonce_str = hex:: encode ( & advert. nonce ) ;
253259
254- let tunnel_id = & derive ( & self . qr_code . qr_secret , None , KeyPurpose :: TunnelID ) [ ..16 ] ;
260+ let tunnel_id = & derive ( & self . qr_code . qr_secret . as_ref ( ) , None , KeyPurpose :: TunnelID ) [ ..16 ] ;
255261 let tunnel_id_str = hex:: encode ( & tunnel_id) ;
256262
257263 let psk: & [ u8 ; 32 ] = & derive (
258- & self . qr_code . qr_secret ,
264+ & self . qr_code . qr_secret . as_ref ( ) ,
259265 Some ( & advert. plaintext ) ,
260266 KeyPurpose :: PSK ,
261267 ) [ ..32 ]
0 commit comments