@@ -110,7 +110,7 @@ PyObject *aws_py_hash_update(PyObject *self, PyObject *args) {
110110 const char * to_hash_c_str ;
111111 Py_ssize_t to_hash_len ;
112112
113- if (!PyArg_ParseTuple (args , "Os #" , & hash_capsule , & to_hash_c_str , & to_hash_len )) {
113+ if (!PyArg_ParseTuple (args , "Oy #" , & hash_capsule , & to_hash_c_str , & to_hash_len )) {
114114 return PyErr_AwsLastError ();
115115 }
116116
@@ -179,7 +179,7 @@ PyObject *aws_py_sha256_hmac_new(PyObject *self, PyObject *args) {
179179 const char * secret_ptr ;
180180 Py_ssize_t secret_len ;
181181
182- if (!PyArg_ParseTuple (args , "s #" , & secret_ptr , & secret_len )) {
182+ if (!PyArg_ParseTuple (args , "y #" , & secret_ptr , & secret_len )) {
183183 return PyErr_AwsLastError ();
184184 }
185185
@@ -202,7 +202,7 @@ PyObject *aws_py_hmac_update(PyObject *self, PyObject *args) {
202202 const char * to_hmac_ptr ;
203203 Py_ssize_t to_hmac_len ;
204204
205- if (!PyArg_ParseTuple (args , "Os #" , & hmac_capsule , & to_hmac_ptr , & to_hmac_len )) {
205+ if (!PyArg_ParseTuple (args , "Oy #" , & hmac_capsule , & to_hmac_ptr , & to_hmac_len )) {
206206 return PyErr_AwsLastError ();
207207 }
208208
@@ -273,7 +273,7 @@ PyObject *aws_py_rsa_private_key_from_pem_data(PyObject *self, PyObject *args) {
273273 (void )self ;
274274
275275 struct aws_byte_cursor pem_data_cur ;
276- if (!PyArg_ParseTuple (args , "s #" , & pem_data_cur .ptr , & pem_data_cur .len )) {
276+ if (!PyArg_ParseTuple (args , "y #" , & pem_data_cur .ptr , & pem_data_cur .len )) {
277277 return NULL ;
278278 }
279279
@@ -323,7 +323,7 @@ PyObject *aws_py_rsa_public_key_from_pem_data(PyObject *self, PyObject *args) {
323323 (void )self ;
324324
325325 struct aws_byte_cursor pem_data_cur ;
326- if (!PyArg_ParseTuple (args , "s #" , & pem_data_cur .ptr , & pem_data_cur .len )) {
326+ if (!PyArg_ParseTuple (args , "y #" , & pem_data_cur .ptr , & pem_data_cur .len )) {
327327 return NULL ;
328328 }
329329
@@ -425,7 +425,7 @@ PyObject *aws_py_rsa_encrypt(PyObject *self, PyObject *args) {
425425 PyObject * rsa_capsule = NULL ;
426426 int encrypt_algo = 0 ;
427427 struct aws_byte_cursor plaintext_cur ;
428- if (!PyArg_ParseTuple (args , "Ois #" , & rsa_capsule , & encrypt_algo , & plaintext_cur .ptr , & plaintext_cur .len )) {
428+ if (!PyArg_ParseTuple (args , "Oiy #" , & rsa_capsule , & encrypt_algo , & plaintext_cur .ptr , & plaintext_cur .len )) {
429429 return NULL ;
430430 }
431431
@@ -793,6 +793,7 @@ PyObject *aws_py_ec_encode_signature(PyObject *self, PyObject *args) {
793793 return NULL ;
794794 }
795795
796+ /* Note: PyBytes_Check does not null check, hence explicit null check before. */
796797 if (!PyBytes_Check (r_bytes ) || !PyBytes_Check (s_bytes )) {
797798 PyErr_SetString (PyExc_TypeError , "r and s must be bytes" );
798799 Py_DECREF (r_bytes );
@@ -836,7 +837,7 @@ PyObject *aws_py_ec_decode_signature(PyObject *self, PyObject *args) {
836837 (void )self ;
837838
838839 struct aws_byte_cursor signature_cur ;
839- if (!PyArg_ParseTuple (args , "s #" , & signature_cur .ptr , & signature_cur .len )) {
840+ if (!PyArg_ParseTuple (args , "y #" , & signature_cur .ptr , & signature_cur .len )) {
840841 return NULL ;
841842 }
842843
@@ -857,3 +858,35 @@ PyObject *aws_py_ec_decode_signature(PyObject *self, PyObject *args) {
857858
858859 return result ;
859860}
861+
862+ PyObject * aws_py_ec_get_public_coords (PyObject * self , PyObject * args ) {
863+ (void )self ;
864+
865+ struct aws_allocator * allocator = aws_py_get_allocator ();
866+ PyObject * ec_capsule = NULL ;
867+ struct aws_byte_cursor digest_cur ;
868+ if (!PyArg_ParseTuple (args , "O" , & ec_capsule )) {
869+ return NULL ;
870+ }
871+
872+ struct aws_ecc_key_pair * ec = PyCapsule_GetPointer (ec_capsule , s_capsule_name_ec );
873+ if (ec == NULL ) {
874+ return NULL ;
875+ }
876+
877+ struct aws_byte_cursor x_cur = {0 };
878+ struct aws_byte_cursor y_cur = {0 };
879+ if (aws_ecc_key_pair_get_public_key (ec , & x_cur , & y_cur )) {
880+ return PyErr_AwsLastError ();
881+ }
882+
883+ PyObject * result = PyTuple_New (2 );
884+ if (!result ) {
885+ return NULL ;
886+ }
887+
888+ PyTuple_SetItem (result , 0 , PyBytes_FromStringAndSize ((char * )x_cur .ptr , x_cur .len ));
889+ PyTuple_SetItem (result , 1 , PyBytes_FromStringAndSize ((char * )y_cur .ptr , y_cur .len ));
890+
891+ return result ;
892+ }
0 commit comments