1 # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 2 # 3 # SPDX-License-Identifier: MPL-2.0 4 # 5 # This Source Code Form is subject to the terms of the Mozilla Public 6 # License, v. 2.0. If a copy of the MPL was not distributed with this 7 # file, you can obtain one at https://mozilla.org/MPL/2.0/. 8 # 9 # See the COPYRIGHT file distributed with this work for additional 10 # information regarding copyright ownership. 11 12 from typing import NamedTuple 13 14 import os 15 16 17 class Algorithm(NamedTuple): 18 name: str 19 number: int 20 bits: int 21 22 @classmethod 23 def default(cls): 24 return cls( 25 os.environ["DEFAULT_ALGORITHM"], 26 int(os.environ["DEFAULT_ALGORITHM_NUMBER"]), 27 int(os.environ["DEFAULT_BITS"]), 28 ) 29 30 31 RSASHA1 = Algorithm("RSASHA1", 5, 2048) 32 NSEC3RSASHA1 = Algorithm("NSEC3RSASHA1", 7, 2048) 33 RSASHA256 = Algorithm("RSASHA256", 8, 2048) 34 RSASHA512 = Algorithm("RSASHA512", 10, 2048) 35 ECDSAP256SHA256 = Algorithm("ECDSAP256SHA256", 13, 256) 36 ECDSAP384SHA384 = Algorithm("ECDSAP384SHA384", 14, 384) 37 ED25519 = Algorithm("ED25519", 15, 256) 38 ED448 = Algorithm("ED448", 16, 456) 39 40 ALL_ALGORITHMS = [ 41 RSASHA1, 42 NSEC3RSASHA1, 43 RSASHA256, 44 RSASHA512, 45 ECDSAP256SHA256, 46 ECDSAP384SHA384, 47 ED25519, 48 ED448, 49 ] 50 51 ALL_ALGORITHMS_BY_NUM = {alg.number: alg for alg in ALL_ALGORITHMS} 52