Skip to content

Commit

Permalink
fixup - fix linting and formatting, as well as variable name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jgough committed Nov 30, 2023
1 parent c416379 commit 61b2831
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions scitt/create_signed_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def open_signing_key(key_file: str) -> SigningKey:
return signing_key


def open_statement(payload: str) -> str:
def open_payload(payload_file: str) -> str:
"""
opens the statement from the statement file.
NOTE: the statement is expected to be in json format.
opens the payload from the payload file.
NOTE: the payload is expected to be in json format.
"""
with open(payload, encoding="UTF-8") as file:
statement = json.loads(file.read())
with open(payload_file, encoding="UTF-8") as file:
payload = json.loads(file.read())

# convert the statement to a cose sign1 payload
payload = json.dumps(statement, ensure_ascii=False)
# convert the payload to a cose sign1 payload
payload = json.dumps(payload, ensure_ascii=False)

return payload

Expand Down Expand Up @@ -91,10 +91,10 @@ def create_signed_statement(
},
}

# create the sign1 message using the protected header and payload
msg = Sign1Message(phdr=protected_header, payload=payload.encode("utf-8"))
# create the statement as a sign1 message using the protected header and payload
statement = Sign1Message(phdr=protected_header, payload=payload.encode("utf-8"))

# create the cose_key to sign the message using the signing key
# create the cose_key to sign the statement using the signing key
cose_key = {
KpKty: KtyEC2,
EC2KpCurve: P256,
Expand All @@ -105,16 +105,16 @@ def create_signed_statement(
}

cose_key = CoseKey.from_dict(cose_key)
msg.key = cose_key
statement.key = cose_key

# sign and cbor encode the cose sign1 message.
# sign and cbor encode the statement.
# NOTE: the encode() function performs the signing automatically
cbor_encoded_msg = msg.encode([None])
signed_statement = statement.encode([None])

# base64 encode the cbor message
b64_encoded_msg = b64encode(cbor_encoded_msg)
# base64 encode the signed statement
signed_statement_b64 = b64encode(signed_statement)

return b64_encoded_msg
return signed_statement_b64


def main():
Expand All @@ -130,23 +130,23 @@ def main():
default="scitt-signing-key.pem",
)

# payload (a reference to the file that will become the payload of the SCITT Statement)
# payload-file (a reference to the file that will become the payload of the SCITT Statement)
parser.add_argument(
"--payload",
"--payload-file",
type=str,
help="filepath to the content that will become the payload of the SCITT Statement (currently limited to json format).",
default="scitt-statement.json",
help="filepath to the content that will become the payload of the SCITT Statement "
"(currently limited to json format).",
default="scitt-payload.json",
)

# content-type
parser.add_argument(
"--content-type",
type=str,
help="The iana.org media type for the payload",
default="scitt-statement.json",
default="application/json",
)


# feed
parser.add_argument(
"--feed",
Expand All @@ -172,7 +172,7 @@ def main():
args = parser.parse_args()

signing_key = open_signing_key(args.signing_key_file)
payload = open_statement(args.payload)
payload = open_payload(args.payload)

signed_statement = create_signed_statement(
signing_key, payload, args.feed, args.issuer
Expand Down

0 comments on commit 61b2831

Please sign in to comment.