17
17
18
18
import abc
19
19
import hashlib
20
- from ctypes import CFUNCTYPE , POINTER , c_bool , c_char , c_size_t , c_uint8 , c_uint32 , c_void_p , memmove , py_object , string_at
20
+ from ctypes import CFUNCTYPE , POINTER , pointer , c_bool , c_char , c_size_t , c_uint8 , c_uint32 , c_void_p , memmove , py_object , string_at , cast
21
21
22
22
from chip import native
23
23
from ecdsa import ECDH , NIST256p , SigningKey # type: ignore
31
31
32
32
33
33
@ _pychip_P256Keypair_ECDSA_sign_msg_func
34
- def _pychip_ECDSA_sign_msg (self_ : 'P256Keypair' , message_buf : POINTER ( c_uint8 ) , message_size : int , signature_buf : POINTER ( c_uint8 ) , signature_buf_size : POINTER ( c_size_t ) ) -> bool :
34
+ def _pychip_ECDSA_sign_msg (self_ : 'P256Keypair' , message_buf : pointer [ c_uint8 ] , message_size : int , signature_buf : pointer [ c_uint8 ] , signature_buf_size : pointer [ c_size_t ] ) -> bool :
35
35
res = self_ .ECDSA_sign_msg (string_at (message_buf , message_size )[:])
36
36
memmove (signature_buf , res , len (res ))
37
- signature_buf_size .content = len (res )
37
+ signature_buf_size .contents . value = len (res )
38
38
return True
39
39
40
40
41
41
@ _pychip_P256Keypair_ECDH_derive_secret_func
42
- def _pychip_ECDH_derive_secret (self_ : 'P256Keypair' , remote_pubkey : POINTER ( c_uint8 ) , out_secret_buf : POINTER ( c_uint8 ) , out_secret_buf_size : POINTER ( c_uint32 ) ) -> bool :
42
+ def _pychip_ECDH_derive_secret (self_ : 'P256Keypair' , remote_pubkey : pointer [ c_uint8 ] , out_secret_buf : pointer [ c_uint8 ] , out_secret_buf_size : pointer [ c_uint32 ] ) -> bool :
43
43
res = self_ .ECDH_derive_secret (string_at (remote_pubkey , P256_PUBLIC_KEY_LENGTH )[:])
44
44
memmove (out_secret_buf , res , len (res ))
45
- out_secret_buf_size .content = len (res )
45
+ out_secret_buf_size .contents . value = len (res )
46
46
return True
47
47
48
48
@@ -79,7 +79,7 @@ def _create_native_object(self) -> c_void_p:
79
79
def __del__ (self ):
80
80
if self ._native_obj is not None :
81
81
handle = native .GetLibraryHandle ()
82
- handle .pychip_DeleteP256Keypair (c_void_p (self ._native_obj ))
82
+ handle .pychip_DeleteP256Keypair (cast (self ._native_obj , c_void_p ))
83
83
self ._native_obj = None
84
84
85
85
@property
@@ -95,7 +95,7 @@ def UpdatePublicKey(self) -> None:
95
95
generates a new keypair.
96
96
'''
97
97
handle = native .GetLibraryHandle ()
98
- handle .pychip_P256Keypair_UpdatePubkey (c_void_p (self .native_object ), self .public_key , len (self .public_key )).raise_on_error ()
98
+ handle .pychip_P256Keypair_UpdatePubkey (cast (self ._native_obj , c_void_p ), self .public_key , len (self .public_key )).raise_on_error ()
99
99
100
100
@abc .abstractproperty
101
101
def public_key (self ) -> bytes :
0 commit comments