Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next Feature Release #145

Merged
merged 21 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,166 @@ def sha1sum(filename: str) -> str:
h.update(byte_block)
return h.hexdigest()

class DataFlow(Enum):
"""
This is out internal representation of the dataFlowType simple type within the CycloneDX standard.

.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/xml/#type_dataFlowType
"""
INBOUND = "inbound"
OUTBOUND = "outbound"
BI_DIRECTIONAL = "bi-directional"
UNKNOWN = "unknown"

class Data:
"""
This is our internal representation of the `dataClassificationType` complex type within the CycloneDX standard.

.. note::
See the CycloneDX Schema for dataClassificationType: https://cyclonedx.org/docs/1.4/xml/#type_dataClassificationType
"""

def __init__(self, flow: DataFlow, classification: str) -> None:
if not flow and not classification:
raise NoPropertiesProvidedException(
'One of `flow` or `classification` must be supplied - neither supplied'
)

self.flow = flow
self.classification = classification

@property
def flow(self) -> DataFlow:
"""
Specifies the data flow for the service.

Returns:
`DataFlow`
"""
return self._flow

@flow.setter
def flow(self, flow: DataFlow) -> None:
self._flow = flow

@property
def classification(self) -> str:
"""
Specifies the classification of the data for the service.

Returns:
`str`
"""
return self._content_type

@classification.setter
def classification(self, classification: str) -> None:
self._classification = classification

class SignatureAlgorithm(Enum):
"""
This is out internal representation of the algorithm simple type within the CycloneDX standard.

.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/json/#tab-pane_signature_oneOf_i2_algorithm_oneOf_i0
"""
RS256 = "RS256"
RS384 = "RS384"
RS512 = "RS512"
PS256 = "PS256"
PS384 = "PS384"
PS512 = "PS512"
ES256 = "ES256"
ES384 = "ES384"
ES512 = "ES512"
ED25519 = "Ed25519"
ED448 = "Ed448"
HS256 = "HS256"
HS384 = "HS384"
HS512 = "HS512"

class SignaturePublicKeyKty(Enum):
"""
This is our internal representation of the kty simple type within the CycloneDX standard.

.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/json/#signature_oneOf_i2_publicKey_kty
"""
EC = "EC"
OKP = "OKP"
RSA = "RSA"

class SignaturePublicKeyCrv(Enum):
"""
This is our internal representation of the crv simple type within the CycloneDX standard.

.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/json/#signature_oneOf_i2_publicKey_allOf_i1_then_crv
"""
ED25519 = "Ed25519"
Ed448 = "Ed448"

class SignaturePublicKey:
"""
This is our internal representation of the public key complex type within the CycloneDX standard.

.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/json/#signature_oneOf_i2_publicKey
JSON only
"""
def __init__(self, kty: SignaturePublicKeyKty = None, crv: Optional[SignaturePublicKeyCrv] = None,
madpah marked this conversation as resolved.
Show resolved Hide resolved
x: Optional[str] = None, y: Optional[str] = None,
n: Optional[str] = None, e: Optional[str] = None,
value: str = None) -> None:
if not kty and not value:
raise NoPropertiesProvidedException(
'`kty` must be supplied'
)
if kty == SignaturePublicKeyKty.EC and not crv and not x and not y:
raise NoPropertiesProvidedException(
'if `kty` equals EC, `crv`, `x` and `y` must be supplied'
)
if kty == SignaturePublicKeyKty.OKP and not crv and not x:
raise NoPropertiesProvidedException(
'if `kty` equals OKP, `crv`, and `x` must be supplied'
)
if kty == SignaturePublicKeyKty.RSA and not n and not e:
raise NoPropertiesProvidedException(
'if `kty` equals RSA, `n`, and `e` must be supplied'
)
self.kty = kty
self.crv = crv
self.x = x
self.y = y
self.n = n
self.e = e
self.value = value
madpah marked this conversation as resolved.
Show resolved Hide resolved

class Signature:
"""
This is out internal representation of the signature complex type within the CycloneDX standard.

.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/json/#signature
JSON only
"""

def __init__(self, algorithm: SignatureAlgorithm, key_id: Optional[str],
public_key: Optional[SignaturePublicKey] = None,
certificate_path: Optional[List[str]] = None,
excludes: Optional[List[str]] = None,
value: str = None) -> None:
madpah marked this conversation as resolved.
Show resolved Hide resolved
if not algorithm and not value:
raise NoPropertiesProvidedException(
'One of `algorithm` or `value` must be supplied - neither supplied'
)
self.algorithm = algorithm
self.key_id = key_id
self.public_key = public_key
self.certificate_path = certificate_path
self.excludes = excludes
self.value = value

class Encoding(Enum):
"""
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx/model/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IssueClassification(Enum):
This is out internal representation of the enum `issueClassification`.

.. note::
See the CycloneDX Schema definition: hhttps://cyclonedx.org/docs/1.4/xml/#type_issueClassification
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_issueClassification
"""
DEFECT = 'defect'
ENHANCEMENT = 'enhancement'
Expand Down
Loading