GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TestKeyUtils   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 19
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_sin_from_pem() 0 3 2
A test_sign() 0 8 1
A test_generate_pem() 0 4 1
1
from bitpay import key_utils as utils
2
import re
3
import unittest
4
from ecdsa import SigningKey, SECP256k1, VerifyingKey
5
from ecdsa import util as ecdsaUtil
6
import binascii
7
import hashlib
8
9
class TestKeyUtils(unittest.TestCase):
10
11
  def test_generate_pem(self):
12
    pem = utils.generate_pem()
13
    match = re.match(r"-----BEGIN EC PRIVATE KEY-----", pem)
14
    self.assertIsNotNone(match)
15
16
  def test_sin_from_pem(self):
17
    pem = '-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1f532dX+0O6QoAcGBSuBBAAK\noUQDQgAEjZcNa6Kdz6GQwXcUD9iJ+t1tJZCx7hpqBuJV2/IrQBfue8jh8H7Q/4vX\nfAArmNMaGotTpjdnymWlMfszzXJhlw==\n-----END EC PRIVATE KEY-----\n'
18
    assert utils.get_sin_from_pem(pem) == 'TeyN4LPrXiG5t2yuSamKqP3ynVk3F52iHrX'
19
20
  def test_sign(self):
21
    pem = '-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1f532dX+0O6QoAcGBSuBBAAK\noUQDQgAEjZcNa6Kdz6GQwXcUD9iJ+t1tJZCx7hpqBuJV2/IrQBfue8jh8H7Q/4vX\nfAArmNMaGotTpjdnymWlMfszzXJhlw==\n-----END EC PRIVATE KEY-----\n'
22
    signed = utils.sign("message", pem)
23
    sk = SigningKey.from_pem(pem)
24
    vk = sk.get_verifying_key()
25
    print(signed)
26
    signed = binascii.unhexlify(signed)
27
    vk.verify(signed, "message".encode(), hashfunc=hashlib.sha256, sigdecode=ecdsaUtil.sigdecode_der)
28
29