Skip to content

Commit 25f112b

Browse files
author
Jussi Kukkonen
committed
gpg: Remove a circular dependency
There is a circular dependency in gpg.constants -> gpg.rsa -> gpg.util -> gpg.constants This is not a problem on python3 or python2 when the imports are done with "import securesystemslib.<mod>" style. However with the "from securesystemslib import <mod>" style python2 decides this is a ImportError. Remove the circular dependency by moving the module variables from constants to another file.
1 parent f0fbeb0 commit 25f112b

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

securesystemslib/gpg/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
import logging
2323
import collections
2424

25+
from securesystemslib import formats
2526
from securesystemslib.gpg import util as gpg_util
2627
from securesystemslib.gpg.exceptions import (PacketVersionNotSupportedError,
2728
SignatureAlgorithmNotSupportedError, KeyNotFoundError, PacketParsingError)
28-
2929
from securesystemslib.gpg.constants import (
3030
PACKET_TYPE_PRIMARY_KEY, PACKET_TYPE_USER_ID, PACKET_TYPE_USER_ATTR,
3131
PACKET_TYPE_SUB_KEY, PACKET_TYPE_SIGNATURE,
3232
SUPPORTED_PUBKEY_PACKET_VERSIONS, SIGNATURE_TYPE_BINARY,
3333
SIGNATURE_TYPE_CERTIFICATES, SIGNATURE_TYPE_SUB_KEY_BINDING,
34-
SUPPORTED_SIGNATURE_PACKET_VERSIONS, SUPPORTED_SIGNATURE_ALGORITHMS,
35-
SIGNATURE_HANDLERS, FULL_KEYID_SUBPACKET, PARTIAL_KEYID_SUBPACKET,
34+
SUPPORTED_SIGNATURE_PACKET_VERSIONS,
35+
FULL_KEYID_SUBPACKET, PARTIAL_KEYID_SUBPACKET,
3636
SHA1,SHA256, SHA512, KEY_EXPIRATION_SUBPACKET, PRIMARY_USERID_SUBPACKET,
3737
SIG_CREATION_SUBPACKET)
38-
39-
from securesystemslib import formats
38+
from securesystemslib.gpg.handlers import (
39+
SIGNATURE_HANDLERS, SUPPORTED_SIGNATURE_ALGORITHMS)
4040

4141
log = logging.getLogger(__name__)
4242

securesystemslib/gpg/constants.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import os
2020

2121
from securesystemslib import process
22-
from securesystemslib.gpg import rsa
23-
from securesystemslib.gpg import dsa
24-
from securesystemslib.gpg import eddsa
2522

2623
log = logging.getLogger(__name__)
2724

@@ -81,31 +78,6 @@ def is_available_gnupg(gnupg):
8178
SUPPORTED_SIGNATURE_PACKET_VERSIONS = {0x04}
8279
SUPPORTED_PUBKEY_PACKET_VERSIONS = {0x04}
8380

84-
# See section 9.1. (public-key algorithms) of RFC4880 (-bis8)
85-
SUPPORTED_SIGNATURE_ALGORITHMS = {
86-
0x01: {
87-
"type":"rsa",
88-
"method": "pgp+rsa-pkcsv1.5",
89-
"handler": rsa
90-
},
91-
0x11: {
92-
"type": "dsa",
93-
"method": "pgp+dsa-fips-180-2",
94-
"handler": dsa
95-
},
96-
0x16: {
97-
"type": "eddsa",
98-
"method": "pgp+eddsa-ed25519",
99-
"handler": eddsa
100-
}
101-
}
102-
103-
SIGNATURE_HANDLERS = {
104-
"rsa": rsa,
105-
"dsa": dsa,
106-
"eddsa": eddsa
107-
}
108-
10981
# The constants for hash algorithms are taken from section 9.4 of RFC4880.
11082
SHA1 = 0x02
11183
SHA256 = 0x08

securesystemslib/gpg/functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
GPG_SIGN_COMMAND,
3131
HAVE_GPG,
3232
NO_GPG_MSG,
33-
SHA256,
33+
SHA256)
34+
from securesystemslib.gpg.handlers import (
3435
SIGNATURE_HANDLERS)
3536

3637
from securesystemslib import process

securesystemslib/gpg/handlers.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
<Module Name>
3+
handlers.py
4+
5+
<Author>
6+
Santiago Torres-Arias <[email protected]>
7+
8+
<Started>
9+
Jan 15, 2020
10+
11+
<Copyright>
12+
See LICENSE for licensing information.
13+
14+
<Purpose>
15+
Provides links from signatures/algorithms to modules implementing
16+
the signature verification and key parsing.
17+
"""
18+
19+
from securesystemslib.gpg import rsa
20+
from securesystemslib.gpg import dsa
21+
from securesystemslib.gpg import eddsa
22+
23+
# See section 9.1. (public-key algorithms) of RFC4880 (-bis8)
24+
SUPPORTED_SIGNATURE_ALGORITHMS = {
25+
0x01: {
26+
"type":"rsa",
27+
"method": "pgp+rsa-pkcsv1.5",
28+
"handler": rsa
29+
},
30+
0x11: {
31+
"type": "dsa",
32+
"method": "pgp+dsa-fips-180-2",
33+
"handler": dsa
34+
},
35+
0x16: {
36+
"type": "eddsa",
37+
"method": "pgp+eddsa-ed25519",
38+
"handler": eddsa
39+
}
40+
}
41+
42+
SIGNATURE_HANDLERS = {
43+
"rsa": rsa,
44+
"dsa": dsa,
45+
"eddsa": eddsa
46+
}

0 commit comments

Comments
 (0)