Skip to content

Commit b5a6497

Browse files
committed
Replaced absolute paths to the components with relative ones.
1 parent a7308f0 commit b5a6497

19 files changed

+485
-471
lines changed

securesystemslib/ecdsa_keys.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
CRYPTO = False
6868

6969
# Perform object format-checking and add ability to handle/raise exceptions.
70-
import securesystemslib.formats
71-
import securesystemslib.exceptions
70+
from . import formats
71+
from . import exceptions
7272

7373
_SUPPORTED_ECDSA_SCHEMES = ['ecdsa-sha2-nistp256']
7474

@@ -136,14 +136,14 @@ def generate_public_and_private(scheme='ecdsa-sha2-nistp256'):
136136
"""
137137

138138
if not CRYPTO: # pragma: no cover
139-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
139+
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
140140

141141
# Does 'scheme' have the correct format?
142142
# Verify that 'scheme' is of the correct type, and that it's one of the
143143
# supported ECDSA . It must conform to
144144
# 'securesystemslib.formats.ECDSA_SCHEME_SCHEMA'. Raise
145145
# 'securesystemslib.exceptions.FormatError' if the check fails.
146-
securesystemslib.formats.ECDSA_SCHEME_SCHEMA.check_match(scheme)
146+
formats.ECDSA_SCHEME_SCHEMA.check_match(scheme)
147147

148148
public_key = None
149149
private_key = None
@@ -158,7 +158,7 @@ def generate_public_and_private(scheme='ecdsa-sha2-nistp256'):
158158
# The ECDSA_SCHEME_SCHEMA.check_match() above should have detected any
159159
# invalid 'scheme'. This is a defensive check.
160160
else: #pragma: no cover
161-
raise securesystemslib.exceptions.UnsupportedAlgorithmError('An unsupported'
161+
raise exceptions.UnsupportedAlgorithmError('An unsupported'
162162
' scheme specified: ' + repr(scheme) + '.\n Supported'
163163
' algorithms: ' + repr(_SUPPORTED_ECDSA_SCHEMES))
164164

@@ -225,19 +225,19 @@ def create_signature(public_key, private_key, data, scheme='ecdsa-sha2-nistp256'
225225
"""
226226

227227
if not CRYPTO: # pragma: no cover
228-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
228+
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
229229

230230
# Do 'public_key' and 'private_key' have the correct format?
231231
# This check will ensure that the arguments conform to
232232
# 'securesystemslib.formats.PEMECDSA_SCHEMA'. Raise
233233
# 'securesystemslib.exceptions.FormatError' if the check fails.
234-
securesystemslib.formats.PEMECDSA_SCHEMA.check_match(public_key)
234+
formats.PEMECDSA_SCHEMA.check_match(public_key)
235235

236236
# Is 'private_key' properly formatted?
237-
securesystemslib.formats.PEMECDSA_SCHEMA.check_match(private_key)
237+
formats.PEMECDSA_SCHEMA.check_match(private_key)
238238

239239
# Is 'scheme' properly formatted?
240-
securesystemslib.formats.ECDSA_SCHEME_SCHEMA.check_match(scheme)
240+
formats.ECDSA_SCHEME_SCHEMA.check_match(scheme)
241241

242242
# 'ecdsa-sha2-nistp256' is the only currently supported ECDSA scheme, so this
243243
# if-clause isn't strictly needed. Nevertheless, the conditional statement
@@ -251,13 +251,13 @@ def create_signature(public_key, private_key, data, scheme='ecdsa-sha2-nistp256'
251251
signature = private_key.sign(data, ec.ECDSA(hashes.SHA256()))
252252

253253
except TypeError as e:
254-
raise securesystemslib.exceptions.CryptoError('Could not create'
254+
raise exceptions.CryptoError('Could not create'
255255
' signature: ' + str(e))
256256

257257
# A defensive check for an invalid 'scheme'. The
258258
# ECDSA_SCHEME_SCHEMA.check_match() above should have already validated it.
259259
else: #pragma: no cover
260-
raise securesystemslib.exceptions.UnsupportedAlgorithmError('Unsupported'
260+
raise exceptions.UnsupportedAlgorithmError('Unsupported'
261261
' signature scheme is specified: ' + repr(scheme))
262262

263263
return signature, scheme
@@ -316,19 +316,19 @@ def verify_signature(public_key, scheme, signature, data):
316316
"""
317317

318318
if not CRYPTO: # pragma: no cover
319-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
319+
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
320320

321321
# Are the arguments properly formatted?
322-
# If not, raise 'securesystemslib.exceptions.FormatError'.
323-
securesystemslib.formats.PEMECDSA_SCHEMA.check_match(public_key)
324-
securesystemslib.formats.ECDSA_SCHEME_SCHEMA.check_match(scheme)
325-
securesystemslib.formats.ECDSASIGNATURE_SCHEMA.check_match(signature)
322+
# If not, raise 'exceptions.FormatError'.
323+
formats.PEMECDSA_SCHEMA.check_match(public_key)
324+
formats.ECDSA_SCHEME_SCHEMA.check_match(scheme)
325+
formats.ECDSASIGNATURE_SCHEMA.check_match(signature)
326326

327327
ecdsa_key = load_pem_public_key(public_key.encode('utf-8'),
328328
backend=default_backend())
329329

330330
if not isinstance(ecdsa_key, ec.EllipticCurvePublicKey):
331-
raise securesystemslib.exceptions.FormatError('Invalid ECDSA public'
331+
raise exceptions.FormatError('Invalid ECDSA public'
332332
' key: ' + repr(public_key))
333333

334334
else:
@@ -399,15 +399,15 @@ def create_ecdsa_public_and_private_from_pem(pem, password=None):
399399
"""
400400

401401
if not CRYPTO: # pragma: no cover
402-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
402+
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
403403

404404
# Does 'pem' have the correct format?
405405
# This check will ensure 'pem' conforms to
406406
# 'securesystemslib.formats.ECDSARSA_SCHEMA'.
407-
securesystemslib.formats.PEMECDSA_SCHEMA.check_match(pem)
407+
formats.PEMECDSA_SCHEMA.check_match(pem)
408408

409409
if password is not None:
410-
securesystemslib.formats.PASSWORD_SCHEMA.check_match(password)
410+
formats.PASSWORD_SCHEMA.check_match(password)
411411
password = password.encode('utf-8')
412412

413413
else:
@@ -424,7 +424,7 @@ def create_ecdsa_public_and_private_from_pem(pem, password=None):
424424
backend=default_backend())
425425

426426
except (ValueError, cryptography.exceptions.UnsupportedAlgorithm) as e:
427-
raise securesystemslib.exceptions.CryptoError('Could not import private'
427+
raise exceptions.CryptoError('Could not import private'
428428
' PEM.\n' + str(e))
429429

430430
public = private.public_key()
@@ -486,14 +486,14 @@ def create_ecdsa_encrypted_pem(private_pem, passphrase):
486486
"""
487487

488488
if not CRYPTO: # pragma: no cover
489-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
489+
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
490490

491491
# Does 'private_key' have the correct format?
492492
# Raise 'securesystemslib.exceptions.FormatError' if the check fails.
493-
securesystemslib.formats.PEMRSA_SCHEMA.check_match(private_pem)
493+
formats.PEMRSA_SCHEMA.check_match(private_pem)
494494

495495
# Does 'passphrase' have the correct format?
496-
securesystemslib.formats.PASSWORD_SCHEMA.check_match(passphrase)
496+
formats.PASSWORD_SCHEMA.check_match(passphrase)
497497

498498
encrypted_pem = None
499499

securesystemslib/ed25519_keys.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@
9191

9292
# The optimized pure Python implementation of Ed25519. If
9393
# PyNaCl cannot be imported and an attempt to use is made in this module, a
94-
# 'securesystemslib.exceptions.UnsupportedLibraryError' exception is raised.
95-
import securesystemslib._vendor.ed25519.ed25519
94+
# 'exceptions.UnsupportedLibraryError' exception is raised.
95+
from ._vendor.ed25519 import ed25519
9696

97-
import securesystemslib.formats
98-
import securesystemslib.exceptions
97+
from . import formats
98+
from . import exceptions
9999

100100
# Supported ed25519 signing schemes: 'ed25519'. The pure Python implementation
101101
# (i.e., ed25519') and PyNaCl (i.e., 'nacl', libsodium + Python bindings)
@@ -145,7 +145,7 @@ def generate_public_and_private():
145145
"""
146146

147147
if not NACL: # pragma: no cover
148-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_NACL_MSG)
148+
raise exceptions.UnsupportedLibraryError(NO_NACL_MSG)
149149

150150
# Generate ed25519's seed key by calling os.urandom(). The random bytes
151151
# returned should be suitable for cryptographic use and is OS-specific.
@@ -225,19 +225,19 @@ def create_signature(public_key, private_key, data, scheme):
225225
"""
226226

227227
if not NACL: # pragma: no cover
228-
raise securesystemslib.exceptions.UnsupportedLibraryError(NO_NACL_MSG)
228+
raise exceptions.UnsupportedLibraryError(NO_NACL_MSG)
229229

230230
# Does 'public_key' have the correct format?
231231
# This check will ensure 'public_key' conforms to
232232
# 'securesystemslib.formats.ED25519PUBLIC_SCHEMA', which must have length 32
233233
# bytes. Raise 'securesystemslib.exceptions.FormatError' if the check fails.
234-
securesystemslib.formats.ED25519PUBLIC_SCHEMA.check_match(public_key)
234+
formats.ED25519PUBLIC_SCHEMA.check_match(public_key)
235235

236236
# Is 'private_key' properly formatted?
237-
securesystemslib.formats.ED25519SEED_SCHEMA.check_match(private_key)
237+
formats.ED25519SEED_SCHEMA.check_match(private_key)
238238

239239
# Is 'scheme' properly formatted?
240-
securesystemslib.formats.ED25519_SIG_SCHEMA.check_match(scheme)
240+
formats.ED25519_SIG_SCHEMA.check_match(scheme)
241241

242242
# Signing the 'data' object requires a seed and public key.
243243
# nacl.signing.SigningKey.sign() generates the signature.
@@ -256,13 +256,13 @@ def create_signature(public_key, private_key, data, scheme):
256256
signature = nacl_sig.signature
257257

258258
except (ValueError, TypeError, nacl.exceptions.CryptoError) as e:
259-
raise securesystemslib.exceptions.CryptoError('An "ed25519" signature'
259+
raise exceptions.CryptoError('An "ed25519" signature'
260260
' could not be created with PyNaCl.' + str(e))
261261

262262
# This is a defensive check for a valid 'scheme', which should have already
263263
# been validated in the check_match() above.
264264
else: #pragma: no cover
265-
raise securesystemslib.exceptions.UnsupportedAlgorithmError('Unsupported'
265+
raise exceptions.UnsupportedAlgorithmError('Unsupported'
266266
' signature scheme is specified: ' + repr(scheme))
267267

268268
return signature, scheme
@@ -316,7 +316,7 @@ def verify_signature(public_key, scheme, signature, data):
316316
317317
<Side Effects>
318318
nacl.signing.VerifyKey.verify() called if available, otherwise
319-
securesystemslib._vendor.ed25519.ed25519.checkvalid() called to do the
319+
ed25519.checkvalid() called to do the
320320
verification.
321321
322322
<Returns>
@@ -327,13 +327,13 @@ def verify_signature(public_key, scheme, signature, data):
327327
# This check will ensure 'public_key' conforms to
328328
# 'securesystemslib.formats.ED25519PUBLIC_SCHEMA', which must have length 32
329329
# bytes. Raise 'securesystemslib.exceptions.FormatError' if the check fails.
330-
securesystemslib.formats.ED25519PUBLIC_SCHEMA.check_match(public_key)
330+
formats.ED25519PUBLIC_SCHEMA.check_match(public_key)
331331

332332
# Is 'scheme' properly formatted?
333-
securesystemslib.formats.ED25519_SIG_SCHEMA.check_match(scheme)
333+
formats.ED25519_SIG_SCHEMA.check_match(scheme)
334334

335335
# Is 'signature' properly formatted?
336-
securesystemslib.formats.ED25519SIGNATURE_SCHEMA.check_match(signature)
336+
formats.ED25519SIGNATURE_SCHEMA.check_match(signature)
337337

338338
# Verify 'signature'. Before returning the Boolean result, ensure 'ed25519'
339339
# was used as the signature scheme.
@@ -353,7 +353,7 @@ def verify_signature(public_key, scheme, signature, data):
353353
# Verify 'ed25519' signature with the pure Python implementation.
354354
else:
355355
try:
356-
securesystemslib._vendor.ed25519.ed25519.checkvalid(signature,
356+
ed25519.checkvalid(signature,
357357
data, public)
358358
valid_signature = True
359359

@@ -367,7 +367,7 @@ def verify_signature(public_key, scheme, signature, data):
367367
else: #pragma: no cover
368368
message = 'Unsupported ed25519 signature scheme: ' + repr(scheme) + '.\n' + \
369369
'Supported schemes: ' + repr(_SUPPORTED_ED25519_SIGNING_SCHEMES) + '.'
370-
raise securesystemslib.exceptions.UnsupportedAlgorithmError(message)
370+
raise exceptions.UnsupportedAlgorithmError(message)
371371

372372
return valid_signature
373373

securesystemslib/formats.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
import time
8080
import six
8181

82-
import securesystemslib.schema as SCHEMA
83-
import securesystemslib.exceptions
82+
from . import schema as SCHEMA
83+
from . import exceptions
8484

8585
# Note that in the schema definitions below, the 'SCHEMA.Object' types allow
8686
# additional keys which are not defined. Thus, any additions to them will be
@@ -409,7 +409,7 @@ def _create_gpg_pubkey_with_subkey_schema(pubkey_schema):
409409
key_schema = KEYID_SCHEMA,
410410
value_schema = KEY_SCHEMA)
411411

412-
ANY_SIGNATURE_SCHEMA = securesystemslib.schema.OneOf([SIGNATURE_SCHEMA,
412+
ANY_SIGNATURE_SCHEMA = SCHEMA.OneOf([SIGNATURE_SCHEMA,
413413
GPG_SIGNATURE_SCHEMA])
414414

415415
# List of ANY_SIGNATURE_SCHEMA.
@@ -475,7 +475,7 @@ def datetime_to_unix_timestamp(datetime_object):
475475
# Raise 'securesystemslib.exceptions.FormatError' if not.
476476
if not isinstance(datetime_object, datetime.datetime):
477477
message = repr(datetime_object) + ' is not a datetime.datetime() object.'
478-
raise securesystemslib.exceptions.FormatError(message)
478+
raise exceptions.FormatError(message)
479479

480480
unix_timestamp = calendar.timegm(datetime_object.timetuple())
481481

@@ -513,7 +513,7 @@ def unix_timestamp_to_datetime(unix_timestamp):
513513

514514
# Is 'unix_timestamp' properly formatted?
515515
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
516-
securesystemslib.formats.UNIX_TIMESTAMP_SCHEMA.check_match(unix_timestamp)
516+
UNIX_TIMESTAMP_SCHEMA.check_match(unix_timestamp)
517517

518518
# Convert 'unix_timestamp' to a 'time.struct_time', in UTC. The Daylight
519519
# Savings Time (DST) flag is set to zero. datetime.fromtimestamp() is not
@@ -553,7 +553,7 @@ def format_base64(data):
553553
return binascii.b2a_base64(data).decode('utf-8').rstrip('=\n ')
554554

555555
except (TypeError, binascii.Error) as e:
556-
raise securesystemslib.exceptions.FormatError('Invalid base64'
556+
raise exceptions.FormatError('Invalid base64'
557557
' encoding: ' + str(e))
558558

559559

@@ -582,7 +582,7 @@ def parse_base64(base64_string):
582582

583583
if not isinstance(base64_string, six.string_types):
584584
message = 'Invalid argument: '+repr(base64_string)
585-
raise securesystemslib.exceptions.FormatError(message)
585+
raise exceptions.FormatError(message)
586586

587587
extra = len(base64_string) % 4
588588
if extra:
@@ -593,7 +593,7 @@ def parse_base64(base64_string):
593593
return binascii.a2b_base64(base64_string.encode('utf-8'))
594594

595595
except (TypeError, binascii.Error) as e:
596-
raise securesystemslib.exceptions.FormatError('Invalid base64'
596+
raise exceptions.FormatError('Invalid base64'
597597
' encoding: ' + str(e))
598598

599599

@@ -660,7 +660,7 @@ def _encode_canonical(object, output_function):
660660
_encode_canonical(value, output_function)
661661
output_function("}")
662662
else:
663-
raise securesystemslib.exceptions.FormatError('I cannot encode '+repr(object))
663+
raise exceptions.FormatError('I cannot encode '+repr(object))
664664

665665

666666
def encode_canonical(object, output_function=None):
@@ -723,9 +723,9 @@ def encode_canonical(object, output_function=None):
723723
try:
724724
_encode_canonical(object, output_function)
725725

726-
except (TypeError, securesystemslib.exceptions.FormatError) as e:
726+
except (TypeError, exceptions.FormatError) as e:
727727
message = 'Could not encode ' + repr(object) + ': ' + str(e)
728-
raise securesystemslib.exceptions.FormatError(message)
728+
raise exceptions.FormatError(message)
729729

730730
# Return the encoded 'object' as a string.
731731
# Note: Implies 'output_function' is None,

securesystemslib/gpg/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
are almost guaranteed to have gpg installed, yet the same assumption can't be
2222
made for the gpgme python bindings.
2323
"""
24+
from __future__ import absolute_import
25+
from . import constants
26+
from . import util
27+
util.constants = constants

0 commit comments

Comments
 (0)