Skip to content

Commit

Permalink
[issue-185] use regex to match blake checksum algorithms in rdf files
Browse files Browse the repository at this point in the history
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed Nov 28, 2022
1 parent 938cb10 commit 9143c97
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions spdx/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
# 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.
import re
from enum import Enum, auto

Exceptions_rdf = {"SHA3256": "SHA3_256", "SHA3384": "SHA3_384", "SHA3512": "SHA3_512", "BLAKE2B256": "BLAKE2B_256",
"BLAKE2B384": "BLAKE2B_384", "BLAKE2V512": "BLAKE2B_512"}


class ChecksumAlgorithmIdentifier(Enum):
Expand All @@ -38,9 +37,11 @@ def checksum_to_rdf(self):

@classmethod
def checksum_from_rdf(cls, identifier: str) -> str:
identifier = identifier.split('_')[-1].upper()
if identifier in Exceptions_rdf:
return Exceptions_rdf[identifier]
identifier = identifier.split('_', 1)[-1].upper()
blake_checksum = re.compile(r"(BLAKE2B)\s*(256|384|512)", re.UNICODE)
match = blake_checksum.match(identifier)
if match:
return match[1] + '_' + match[2]
return identifier


Expand Down

0 comments on commit 9143c97

Please sign in to comment.