forked from luci/python-adb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_pythonrsa_test.py
executable file
·68 lines (60 loc) · 2.86 KB
/
sign_pythonrsa_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import sys
import unittest
from adb import sign_pythonrsa
class Test(unittest.TestCase):
# openssl genrsa 2048 | openssl pkcs8 -topk8 -inform pem -outform pem -nocrypt
TEST_KEY = r"""
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDkX+itb6GgmKSI
9+1vnYCZvm8edqB9DSVuQUnKjougISl6m74U5YR0dsonpgaHttAEtlwCpY8gS5tA
Hzbr3kLXPoM+XxmxRwklfY0hlQm/Jfksag5W074TDzEe+0tWnY4xKJepi47tWTap
HPYAgqHCUmLnHIE5oMbaew4LjjRZYD3hcs0JtiSEN2rf+gLuhfowTPOkIsBZMvM1
KicRXX3dUna+BIJIP7QRqW1RDPYD0O7LVI4qh7lQ0AQb82REXILwJ9DprNBKojFt
RdIRLzTYPJOrNCY89k/xY/baXvdoUUvOB9uY2QLS1yZGVZy/UIlRF5dMkvqEu35e
vCFrEYXRAgMBAAECggEAHaP9FRWaCrgFEunq3UO5/zpiPbfz2IcuRoMeyrV5lcz4
DzvLjfbEHEGWt1KrIk4t7Y6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gs63Lo4GPKF
oShjkmSqylt4CG34EcCl+JkRTZVFsvp4f8gxC1yQasPo9xjB3DC7maanjp70uMLw
+wAUeW7AMn5lsETmXc+Reg==
-----END PRIVATE KEY-----
""".strip()
def test_sign(self):
# Does not crash => works.
signer = sign_pythonrsa.PythonRSASigner('pub', self.TEST_KEY)
self.assertTrue(signer.Sign('data to sign'))
if __name__ == '__main__':
if '-v' in sys.argv:
unittest.TestCase.maxDiff = None # pragma: no cover
logging.basicConfig(
level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
unittest.main()