-
Notifications
You must be signed in to change notification settings - Fork 64
feat: Enable signing with pre-computed hash #860
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e5875d1
backup
laurentsimon fd9af21
backup
laurentsimon daea2f0
backup
laurentsimon 97bb8f0
backup
laurentsimon 479bbad
remove test code in cli
laurentsimon 027087e
Fix typo
laurentsimon 54d0fe0
cleanup
laurentsimon 31c1cce
Fix typo
laurentsimon 9f20e28
Add hash name conversion
laurentsimon fe29ba8
cleanup
laurentsimon 857ed2a
linter
laurentsimon 64822e6
Fix
laurentsimon a0c2697
Change API
laurentsimon 0271ef1
Remove dirhash example code
laurentsimon 3831c3d
typo
laurentsimon eb13ae9
comments
laurentsimon 9510d20
rebase
laurentsimon a99e1e6
Fix
laurentsimon ef820de
Fix hash
laurentsimon a3b6d9a
Update CHANGELOG
laurentsimon 09fa648
Fix
laurentsimon e583a59
Make functions private
laurentsimon 16058cb
Remove tests code
laurentsimon 7d84139
hashes: format
woodruffw 43dddc5
sigstore: docstrings
woodruffw 69dad22
hashes: docstring
woodruffw 513803e
test: add a prehashed signing test
woodruffw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright 2023 The Sigstore Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Hashing APIs. | ||
| """ | ||
|
|
||
| import rekor_types | ||
| from cryptography.hazmat.primitives import hashes | ||
| from cryptography.hazmat.primitives.asymmetric.utils import Prehashed | ||
| from pydantic import BaseModel | ||
| from sigstore_protobuf_specs.dev.sigstore.common.v1 import HashAlgorithm | ||
|
|
||
|
|
||
| class Hashed(BaseModel): | ||
| """ | ||
| Represents a hashed value. | ||
| """ | ||
|
|
||
| algorithm: HashAlgorithm | ||
| """ | ||
| The digest algorithm uses to compute the digest. | ||
| """ | ||
|
|
||
| digest: bytes | ||
| """ | ||
| The digest representing the hash value. | ||
| """ | ||
|
|
||
| def _as_hashedrekord_algorithm(self) -> rekor_types.hashedrekord.Algorithm: | ||
| """ | ||
| Returns an appropriate `hashedrekord.Algorithm` for this `Hashed`. | ||
| """ | ||
| if self.algorithm == HashAlgorithm.SHA2_256: | ||
| return rekor_types.hashedrekord.Algorithm.SHA256 | ||
| raise ValueError(f"unknown hash algorithm: {self.algorithm}") | ||
|
|
||
| def _as_prehashed(self) -> Prehashed: | ||
| """ | ||
| Returns an appropriate Cryptography `Prehashed` for this `Hashed`. | ||
| """ | ||
| if self.algorithm == HashAlgorithm.SHA2_256: | ||
| return Prehashed(hashes.SHA256()) | ||
| raise ValueError(f"unknown hash algorithm: {self.algorithm}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.