Skip to content

Commit

Permalink
Merge pull request #34 from lukpueh/adds-public-key-schema
Browse files Browse the repository at this point in the history
Adds PUBLIC_KEY_SCHEMA and PUBLIC_KEYVAL_SCHEMA
  • Loading branch information
vladimir-v-diaz authored Jan 20, 2017
2 parents be5091a + 6a1b3f6 commit 4c174fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions securesystemslib/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@
public = SCHEMA.AnyString(),
private = SCHEMA.Optional(SCHEMA.AnyString()))

# Public keys CAN have a private portion (for backwards compatibility) which
# MUST be an empty string
PUBLIC_KEYVAL_SCHEMA = SCHEMA.Object(
object_name = 'KEYVAL_SCHEMA',
public = SCHEMA.AnyString(),
private = SCHEMA.Optional(SCHEMA.String("")))

# Supported TUF key types.
KEYTYPE_SCHEMA = SCHEMA.OneOf(
[SCHEMA.String('rsa'), SCHEMA.String('ed25519'),
Expand All @@ -230,6 +237,13 @@
keyval = KEYVAL_SCHEMA,
expires = SCHEMA.Optional(ISO8601_DATETIME_SCHEMA))

# Like KEY_SCHEMA, but requires keyval's private portion to be not set or empty
PUBLIC_KEY_SCHEMA = SCHEMA.Object(
object_name = 'KEY_SCHEMA',
keytype = SCHEMA.AnyString(),
keyval = PUBLIC_KEYVAL_SCHEMA,
expires = SCHEMA.Optional(ISO8601_DATETIME_SCHEMA))

# A TUF key object. This schema simplifies validation of keys that may be
# one of the supported key types.
# Supported key types: 'rsa', 'ed25519'.
Expand Down
15 changes: 15 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,26 @@ def test_schemas(self):
'KEYVAL_SCHEMA': (securesystemslib.formats.KEYVAL_SCHEMA,
{'public': 'pubkey', 'private': 'privkey'}),

'PUBLIC_KEYVAL_SCHEMA': (securesystemslib.formats.PUBLIC_KEYVAL_SCHEMA,
{'public': 'pubkey'}),

'PUBLIC_KEYVAL_SCHEMA2': (securesystemslib.formats.PUBLIC_KEYVAL_SCHEMA,
{'public': 'pubkey', 'private': ''}),

'KEY_SCHEMA': (securesystemslib.formats.KEY_SCHEMA,
{'keytype': 'rsa',
'keyval': {'public': 'pubkey',
'private': 'privkey'}}),

'PUBLIC_KEY_SCHEMA': (securesystemslib.formats.KEY_SCHEMA,
{'keytype': 'rsa',
'keyval': {'public': 'pubkey'}}),

'PUBLIC_KEY_SCHEMA2': (securesystemslib.formats.KEY_SCHEMA,
{'keytype': 'rsa',
'keyval': {'public': 'pubkey',
'private': ''}}),

'RSAKEY_SCHEMA': (securesystemslib.formats.RSAKEY_SCHEMA,
{'keytype': 'rsa',
'keyid': '123456789abcdef',
Expand Down

0 comments on commit 4c174fd

Please sign in to comment.