aboutsummaryrefslogblamecommitdiff
path: root/frozen_deps/ecdsa/test_keys.py
blob: 406a5bf6e7c5b25eafa78fd95ff0f2a6e464abe5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                          








                            









                                                                      




                                                                  






                                                        

                                                                      

                                     

                                                                       
















                                                                        
                                              




                                                             
                                              




                                                             
                                              




                                                             
                                              




                                                             
                                                               



                                                             
                                                                          



                                                             
                                                                    



                                                             
                                                                               








                                                                   
 






                                                                                

                                            



                                                                                

                                        













































                                                                                
                                              




                                                             
                                              


















                                                                 
 






                                                                                












                                                                                




                                                                                







                                                              
                                      



























                                                         

                                               
 


                                                              
 





                                                                        

                                    




                                   





                                              

















                                                             




                                                                               






                                                              






                                                

                                                













                                                                               

                         

                                                                  
                             

                                                          





                                                          



                                                    


                               










                                                                               














                                                                        

                                    













                                                                      

                                                   



                                                

                                                           







                                                       

                                                                















                                               






                                                                            
try:
    import unittest2 as unittest
except ImportError:
    import unittest

try:
    buffer
except NameError:
    buffer = memoryview

import array
import six
import sys
import pytest
import hashlib

from .keys import VerifyingKey, SigningKey
from .der import unpem
from .util import (
    sigencode_string,
    sigencode_der,
    sigencode_strings,
    sigdecode_string,
    sigdecode_der,
    sigdecode_strings,
)
from .curves import NIST256p


class TestVerifyingKeyFromString(unittest.TestCase):
    """
    Verify that ecdsa.keys.VerifyingKey.from_string() can be used with
    bytes-like objects
    """

    @classmethod
    def setUpClass(cls):
        cls.key_bytes = (
            b"\x04L\xa2\x95\xdb\xc7Z\xd7\x1f\x93\nz\xcf\x97\xcf"
            b"\xd7\xc2\xd9o\xfe8}X!\xae\xd4\xfah\xfa^\rpI\xba\xd1"
            b"Y\xfb\x92xa\xebo+\x9cG\xfav\xca"
        )
        cls.vk = VerifyingKey.from_string(cls.key_bytes)

    def test_bytes(self):
        self.assertIsNotNone(self.vk)
        self.assertIsInstance(self.vk, VerifyingKey)
        self.assertEqual(
            self.vk.pubkey.point.x(),
            105419898848891948935835657980914000059957975659675736097,
        )
        self.assertEqual(
            self.vk.pubkey.point.y(),
            4286866841217412202667522375431381222214611213481632495306,
        )

    def test_bytes_memoryview(self):
        vk = VerifyingKey.from_string(buffer(self.key_bytes))

        self.assertEqual(self.vk.to_string(), vk.to_string())

    def test_bytearray(self):
        vk = VerifyingKey.from_string(bytearray(self.key_bytes))

        self.assertEqual(self.vk.to_string(), vk.to_string())

    def test_bytesarray_memoryview(self):
        vk = VerifyingKey.from_string(buffer(bytearray(