Completed
Pull Request — master (#138)
by
unknown
20:13
created

wechatpy.enterprise.PrpCrypto   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
wmc 2
1 10
from __future__ import absolute_import, unicode_literals
2
3 10
from wechatpy.crypto import BasePrpCrypto, BaseWeChatCrypto
4 10
from wechatpy.enterprise.exceptions import InvalidCorpIdException
5
6
7 10
class PrpCrypto(BasePrpCrypto):
8
9 10
    def encrypt(self, text, corp_id):
10 10
        return self._encrypt(text, corp_id)
11
12 10
    def decrypt(self, text, corp_id):
13 10
        return self._decrypt(text, corp_id, InvalidCorpIdException)
14
15
16 10
class WeChatCrypto(BaseWeChatCrypto):
17
18 10
    def __init__(self, token, encoding_aes_key, corp_id):
19 10
        super(WeChatCrypto, self).__init__(token, encoding_aes_key, corp_id)
20 10
        self.corp_id = corp_id
21
22 10
    def check_signature(self, signature, timestamp, nonce, echo_str):
23 10
        return self._check_signature(
24
            signature,
25
            timestamp,
26
            nonce,
27
            echo_str,
28
            PrpCrypto
29
        )
30
31 10
    def encrypt_message(self, msg, nonce, timestamp=None):
32 10
        return self._encrypt_message(
33
            msg,
34
            nonce,
35
            timestamp,
36
            PrpCrypto
37
        )
38
39 10
    def decrypt_message(self, msg, signature, timestamp, nonce):
40 10
        return self._decrypt_message(
41
            msg,
42
            signature,
43
            timestamp,
44
            nonce,
45
            PrpCrypto
46
        )
47