11//! Creating and parsing devices.
22
33use crate :: {
4- binary_format:: { self } ,
4+ binary_format:: { self , device :: PRD_SCALAR_SIZE } ,
55 certificate:: CertificateChain ,
6- crypto:: ecc_p256:: { FromBytes , Keypair , ToUntaggedBytes } ,
6+ crypto:: ecc_p256:: { FromBytes , Keypair , ToUntaggedBytes , SCALAR_SIZE } ,
77} ;
88use binrw:: { BinRead , BinWrite } ;
99use p256:: ecdsa:: SigningKey ;
@@ -50,7 +50,7 @@ impl Device {
5050 } ;
5151
5252 let group_key = match group_key {
53- Some ( group_key) => Some ( SigningKey :: from_slice ( & group_key[ ..32 ] ) ?) ,
53+ Some ( group_key) => Some ( SigningKey :: from_slice ( & group_key[ ..SCALAR_SIZE ] ) ?) ,
5454 None => None ,
5555 } ;
5656
@@ -64,8 +64,8 @@ impl Device {
6464 binary_format:: device:: DeviceInner :: V3 ( v3) => & v3. signing_key ,
6565 } ;
6666
67- let encryption_key = Keypair :: from_bytes ( & encryption_key[ ..32 ] ) ?;
68- let signing_key = SigningKey :: from_slice ( & signing_key[ ..32 ] ) ?;
67+ let encryption_key = Keypair :: from_bytes ( & encryption_key[ ..SCALAR_SIZE ] ) ?;
68+ let signing_key = SigningKey :: from_slice ( & signing_key[ ..SCALAR_SIZE ] ) ?;
6969
7070 let group_certificate = match device. inner {
7171 binary_format:: device:: DeviceInner :: V2 ( v2) => v2. group_certificate ,
@@ -202,7 +202,7 @@ impl Device {
202202 bytes. clear ( ) ;
203203 file. read_to_end ( & mut bytes) ?;
204204
205- let group_key = SigningKey :: from_slice ( bytes. get ( ..32 ) . ok_or (
205+ let group_key = SigningKey :: from_slice ( bytes. get ( ..SCALAR_SIZE ) . ok_or (
206206 crate :: Error :: SliceOutOfBoundsError ( "group_key" , bytes. len ( ) ) ,
207207 ) ?) ?;
208208
@@ -211,21 +211,21 @@ impl Device {
211211
212212 /// Serializes and writes device to file specified by path.
213213 pub fn write_to_file ( & self , path : impl AsRef < Path > ) -> Result < ( ) , crate :: Error > {
214- let mut group_key = [ 0u8 ; 96 ] ;
215- let mut encryption_key = [ 0u8 ; 96 ] ;
216- let mut signing_key = [ 0u8 ; 96 ] ;
214+ let mut group_key = [ 0u8 ; PRD_SCALAR_SIZE ] ;
215+ let mut encryption_key = [ 0u8 ; PRD_SCALAR_SIZE ] ;
216+ let mut signing_key = [ 0u8 ; PRD_SCALAR_SIZE ] ;
217217
218- group_key[ ..32 ] . copy_from_slice (
218+ group_key[ ..SCALAR_SIZE ] . copy_from_slice (
219219 & self
220220 . group_key
221221 . as_ref ( )
222222 . ok_or ( crate :: Error :: GroupKeyMissingError ) ?
223223 . to_bytes ( ) ,
224224 ) ;
225225
226- encryption_key[ ..32 ]
226+ encryption_key[ ..SCALAR_SIZE ]
227227 . copy_from_slice ( & self . encryption_key . secret ( ) . expose_scalar ( ) . to_repr ( ) ) ;
228- signing_key[ ..32 ] . copy_from_slice ( & self . signing_key . to_bytes ( ) ) ;
228+ signing_key[ ..SCALAR_SIZE ] . copy_from_slice ( & self . signing_key . to_bytes ( ) ) ;
229229
230230 let group_certificate = self . group_certificate ( ) . to_vec ( ) ;
231231 let group_certificate_length = u32:: try_from ( group_certificate. len ( ) ) . unwrap ( ) ;
0 commit comments