diff --git a/src/gen.zig b/src/gen.zig index 267302d..3ae58a3 100644 --- a/src/gen.zig +++ b/src/gen.zig @@ -80,40 +80,9 @@ pub fn main() !void { try output_file.writeAll("});\n\n"); } - // MultiCodeName + // Codecs try output_file.writeAll( - \\pub const MultiCodeName = enum { - \\ - ); - - lines.reset(); - { - // Skip the header - _ = lines.next(); - - while (lines.next()) |line| { - var fields = std.mem.tokenize(u8, line, ","); - - const name = std.mem.trim(u8, fields.next() orelse break, " "); - - const name_replaced = try allocator.dupe(u8, name); - std.mem.replaceScalar(u8, name_replaced, '-', '_'); - - const string = try std.fmt.allocPrint( - allocator, - "{s},\n", - .{name_replaced}, - ); - defer allocator.free(string); - - try output_file.writeAll(string); - } - try output_file.writeAll("};\n\n"); - } - - // MultiCodeCode - try output_file.writeAll( - \\pub const MultiCodeCode = enum(u32) { + \\pub const Codec = enum(u32) { \\ ); diff --git a/src/lib.zig b/src/lib.zig index ee2e641..377931b 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -2,7 +2,7 @@ const std = @import("std"); const table = @import("table.zig"); const muvarint = @import("muvarint"); -pub fn getCodecByName(name: table.MultiCodeName) !table.Multicodec { +pub fn getCodecByName(name: table.Codec) !table.Multicodec { return table.multicodecTable.get(@tagName(name)) orelse return error.InvalidCodecName; } @@ -20,7 +20,7 @@ pub fn getCodecByCode(code: anytype) !table.Multicodec { return codec; } -pub fn addNamePrefix(allocator: std.mem.Allocator, name: table.MultiCodeName, data: []u8) ![]u8 { +pub fn addNamePrefix(allocator: std.mem.Allocator, name: table.Codec, data: []u8) ![]u8 { const multicodec = try getCodecByName(name); if (multicodec.status != table.Status.Permanent) { return error.CodecNotPermanent; @@ -50,44 +50,44 @@ pub fn split(data: []u8) !struct { codec: table.Multicodec, data: []const u8 } { test "getCodecByName" { { - const codec = try getCodecByName(table.MultiCodeName.raw); + const codec = try getCodecByName(table.Codec.raw); try std.testing.expect(std.mem.eql(u8, codec.name, "raw")); } { - const codec = try getCodecByName(table.MultiCodeName.lamport_sha3_512_priv_share); + const codec = try getCodecByName(table.Codec.lamport_sha3_512_priv_share); try std.testing.expect(std.mem.eql(u8, codec.name, "lamport-sha3-512-priv-share")); } } test "getCodecByCode" { { - const codec = try getCodecByCode(@intFromEnum(table.MultiCodeCode.raw)); + const codec = try getCodecByCode(@intFromEnum(table.Codec.raw)); try std.testing.expect(std.mem.eql(u8, codec.name, "raw")); } { - const codec = try getCodecByCode(@intFromEnum(table.MultiCodeCode.lamport_sha3_512_priv_share)); + const codec = try getCodecByCode(@intFromEnum(table.Codec.lamport_sha3_512_priv_share)); try std.testing.expect(std.mem.eql(u8, codec.name, "lamport-sha3-512-priv-share")); } } test "addNamePrefix" { var input: [5]u8 = [_]u8{ 104, 101, 108, 108, 111 }; - const value = try addNamePrefix(std.testing.allocator, table.MultiCodeName.raw, input[0..]); + const value = try addNamePrefix(std.testing.allocator, table.Codec.raw, input[0..]); defer std.testing.allocator.free(value); try std.testing.expect(std.mem.eql(u8, value, &[6]u8{ 85, 104, 101, 108, 108, 111 })); } test "getCodec" { var input: [5]u8 = [_]u8{ 104, 101, 108, 108, 111 }; - const prefixed = try addNamePrefix(std.testing.allocator, table.MultiCodeName.raw, input[0..]); + const prefixed = try addNamePrefix(std.testing.allocator, table.Codec.raw, input[0..]); defer std.testing.allocator.free(prefixed); const codec = try getCodec(prefixed); - try std.testing.expectEqual(codec.code, @intFromEnum(table.MultiCodeCode.raw)); + try std.testing.expectEqual(codec.code, @intFromEnum(table.Codec.raw)); } test "getData" { var input: [5]u8 = [_]u8{ 104, 101, 108, 108, 111 }; - const prefixed = try addNamePrefix(std.testing.allocator, table.MultiCodeName.raw, input[0..]); + const prefixed = try addNamePrefix(std.testing.allocator, table.Codec.raw, input[0..]); defer std.testing.allocator.free(prefixed); const data = try getData(prefixed); try std.testing.expect(std.mem.eql(u8, data, &[5]u8{ 104, 101, 108, 108, 111 })); @@ -95,10 +95,10 @@ test "getData" { test "split" { var input: [5]u8 = [_]u8{ 104, 101, 108, 108, 111 }; - const prefixed = try addNamePrefix(std.testing.allocator, table.MultiCodeName.raw, input[0..]); + const prefixed = try addNamePrefix(std.testing.allocator, table.Codec.raw, input[0..]); defer std.testing.allocator.free(prefixed); const codec_and_data = try split(prefixed); try std.testing.expect(std.mem.eql(u8, prefixed, &[6]u8{ 85, 104, 101, 108, 108, 111 })); - try std.testing.expectEqual(codec_and_data.codec.code, @intFromEnum(table.MultiCodeCode.raw)); + try std.testing.expectEqual(codec_and_data.codec.code, @intFromEnum(table.Codec.raw)); try std.testing.expect(std.mem.eql(u8, codec_and_data.data, &[5]u8{ 104, 101, 108, 108, 111 })); } diff --git a/src/table.zig b/src/table.zig index b399a2d..e809b08 100644 --- a/src/table.zig +++ b/src/table.zig @@ -598,595 +598,7 @@ pub const multicodecTable = std.StaticStringMap(Multicodec).initComptime(.{ .{ "scion", .{ .name = "scion", .tag = "multiaddr", .code = 0xd02000, .status = Status.Draft, .description = " SCION Internet architecture" } }, }); -pub const MultiCodeName = enum { - identity, - cidv1, - cidv2, - cidv3, - ip4, - tcp, - sha1, - sha2_256, - sha2_512, - sha3_512, - sha3_384, - sha3_256, - sha3_224, - shake_128, - shake_256, - keccak_224, - keccak_256, - keccak_384, - keccak_512, - blake3, - sha2_384, - dccp, - murmur3_x64_64, - murmur3_32, - ip6, - ip6zone, - ipcidr, - path, - multicodec, - multihash, - multiaddr, - multibase, - varsig, - dns, - dns4, - dns6, - dnsaddr, - protobuf, - cbor, - raw, - dbl_sha2_256, - rlp, - bencode, - dag_pb, - dag_cbor, - libp2p_key, - git_raw, - torrent_info, - torrent_file, - blake3_hashseq, - leofcoin_block, - leofcoin_tx, - leofcoin_pr, - sctp, - dag_jose, - dag_cose, - lbry, - eth_block, - eth_block_list, - eth_tx_trie, - eth_tx, - eth_tx_receipt_trie, - eth_tx_receipt, - eth_state_trie, - eth_account_snapshot, - eth_storage_trie, - eth_receipt_log_trie, - eth_receipt_log, - aes_128, - aes_192, - aes_256, - chacha_128, - chacha_256, - bitcoin_block, - bitcoin_tx, - bitcoin_witness_commitment, - zcash_block, - zcash_tx, - caip_50, - streamid, - stellar_block, - stellar_tx, - md4, - md5, - decred_block, - decred_tx, - ipld, - ipfs, - swarm, - ipns, - zeronet, - secp256k1_pub, - dnslink, - bls12_381_g1_pub, - bls12_381_g2_pub, - x25519_pub, - ed25519_pub, - bls12_381_g1g2_pub, - sr25519_pub, - dash_block, - dash_tx, - swarm_manifest, - swarm_feed, - beeson, - udp, - p2p_webrtc_star, - p2p_webrtc_direct, - p2p_stardust, - webrtc_direct, - webrtc, - p2p_circuit, - dag_json, - udt, - utp, - crc32, - crc64_ecma, - unix, - thread, - p2p, - https, - onion, - onion3, - garlic64, - garlic32, - tls, - sni, - noise, - shs, - quic, - quic_v1, - webtransport, - certhash, - ws, - wss, - p2p_websocket_star, - http, - http_path, - swhid_1_snp, - json, - messagepack, - car, - ipns_record, - libp2p_peer_record, - libp2p_relay_rsvp, - memorytransport, - car_index_sorted, - car_multihash_index_sorted, - transport_bitswap, - transport_graphsync_filecoinv1, - transport_ipfs_gateway_http, - multidid, - sha2_256_trunc254_padded, - sha2_224, - sha2_512_224, - sha2_512_256, - murmur3_x64_128, - ripemd_128, - ripemd_160, - ripemd_256, - ripemd_320, - x11, - p256_pub, - p384_pub, - p521_pub, - ed448_pub, - x448_pub, - rsa_pub, - sm2_pub, - vlad, - provenance_log, - provenance_log_entry, - provenance_log_script, - mlkem_512_pub, - mlkem_768_pub, - mlkem_1024_pub, - multisig, - multikey, - nonce, - ed25519_priv, - secp256k1_priv, - x25519_priv, - sr25519_priv, - rsa_priv, - p256_priv, - p384_priv, - p521_priv, - bls12_381_g1_priv, - bls12_381_g2_priv, - bls12_381_g1g2_priv, - bls12_381_g1_pub_share, - bls12_381_g2_pub_share, - bls12_381_g1_priv_share, - bls12_381_g2_priv_share, - lamport_sha3_512_pub, - lamport_sha3_384_pub, - lamport_sha3_256_pub, - lamport_sha3_512_priv, - lamport_sha3_384_priv, - lamport_sha3_256_priv, - lamport_sha3_512_priv_share, - lamport_sha3_384_priv_share, - lamport_sha3_256_priv_share, - lamport_sha3_512_sig, - lamport_sha3_384_sig, - lamport_sha3_256_sig, - lamport_sha3_512_sig_share, - lamport_sha3_384_sig_share, - lamport_sha3_256_sig_share, - kangarootwelve, - aes_gcm_256, - silverpine, - sm3_256, - sha256a, - chacha20_poly1305, - blake2b_8, - blake2b_16, - blake2b_24, - blake2b_32, - blake2b_40, - blake2b_48, - blake2b_56, - blake2b_64, - blake2b_72, - blake2b_80, - blake2b_88, - blake2b_96, - blake2b_104, - blake2b_112, - blake2b_120, - blake2b_128, - blake2b_136, - blake2b_144, - blake2b_152, - blake2b_160, - blake2b_168, - blake2b_176, - blake2b_184, - blake2b_192, - blake2b_200, - blake2b_208, - blake2b_216, - blake2b_224, - blake2b_232, - blake2b_240, - blake2b_248, - blake2b_256, - blake2b_264, - blake2b_272, - blake2b_280, - blake2b_288, - blake2b_296, - blake2b_304, - blake2b_312, - blake2b_320, - blake2b_328, - blake2b_336, - blake2b_344, - blake2b_352, - blake2b_360, - blake2b_368, - blake2b_376, - blake2b_384, - blake2b_392, - blake2b_400, - blake2b_408, - blake2b_416, - blake2b_424, - blake2b_432, - blake2b_440, - blake2b_448, - blake2b_456, - blake2b_464, - blake2b_472, - blake2b_480, - blake2b_488, - blake2b_496, - blake2b_504, - blake2b_512, - blake2s_8, - blake2s_16, - blake2s_24, - blake2s_32, - blake2s_40, - blake2s_48, - blake2s_56, - blake2s_64, - blake2s_72, - blake2s_80, - blake2s_88, - blake2s_96, - blake2s_104, - blake2s_112, - blake2s_120, - blake2s_128, - blake2s_136, - blake2s_144, - blake2s_152, - blake2s_160, - blake2s_168, - blake2s_176, - blake2s_184, - blake2s_192, - blake2s_200, - blake2s_208, - blake2s_216, - blake2s_224, - blake2s_232, - blake2s_240, - blake2s_248, - blake2s_256, - skein256_8, - skein256_16, - skein256_24, - skein256_32, - skein256_40, - skein256_48, - skein256_56, - skein256_64, - skein256_72, - skein256_80, - skein256_88, - skein256_96, - skein256_104, - skein256_112, - skein256_120, - skein256_128, - skein256_136, - skein256_144, - skein256_152, - skein256_160, - skein256_168, - skein256_176, - skein256_184, - skein256_192, - skein256_200, - skein256_208, - skein256_216, - skein256_224, - skein256_232, - skein256_240, - skein256_248, - skein256_256, - skein512_8, - skein512_16, - skein512_24, - skein512_32, - skein512_40, - skein512_48, - skein512_56, - skein512_64, - skein512_72, - skein512_80, - skein512_88, - skein512_96, - skein512_104, - skein512_112, - skein512_120, - skein512_128, - skein512_136, - skein512_144, - skein512_152, - skein512_160, - skein512_168, - skein512_176, - skein512_184, - skein512_192, - skein512_200, - skein512_208, - skein512_216, - skein512_224, - skein512_232, - skein512_240, - skein512_248, - skein512_256, - skein512_264, - skein512_272, - skein512_280, - skein512_288, - skein512_296, - skein512_304, - skein512_312, - skein512_320, - skein512_328, - skein512_336, - skein512_344, - skein512_352, - skein512_360, - skein512_368, - skein512_376, - skein512_384, - skein512_392, - skein512_400, - skein512_408, - skein512_416, - skein512_424, - skein512_432, - skein512_440, - skein512_448, - skein512_456, - skein512_464, - skein512_472, - skein512_480, - skein512_488, - skein512_496, - skein512_504, - skein512_512, - skein1024_8, - skein1024_16, - skein1024_24, - skein1024_32, - skein1024_40, - skein1024_48, - skein1024_56, - skein1024_64, - skein1024_72, - skein1024_80, - skein1024_88, - skein1024_96, - skein1024_104, - skein1024_112, - skein1024_120, - skein1024_128, - skein1024_136, - skein1024_144, - skein1024_152, - skein1024_160, - skein1024_168, - skein1024_176, - skein1024_184, - skein1024_192, - skein1024_200, - skein1024_208, - skein1024_216, - skein1024_224, - skein1024_232, - skein1024_240, - skein1024_248, - skein1024_256, - skein1024_264, - skein1024_272, - skein1024_280, - skein1024_288, - skein1024_296, - skein1024_304, - skein1024_312, - skein1024_320, - skein1024_328, - skein1024_336, - skein1024_344, - skein1024_352, - skein1024_360, - skein1024_368, - skein1024_376, - skein1024_384, - skein1024_392, - skein1024_400, - skein1024_408, - skein1024_416, - skein1024_424, - skein1024_432, - skein1024_440, - skein1024_448, - skein1024_456, - skein1024_464, - skein1024_472, - skein1024_480, - skein1024_488, - skein1024_496, - skein1024_504, - skein1024_512, - skein1024_520, - skein1024_528, - skein1024_536, - skein1024_544, - skein1024_552, - skein1024_560, - skein1024_568, - skein1024_576, - skein1024_584, - skein1024_592, - skein1024_600, - skein1024_608, - skein1024_616, - skein1024_624, - skein1024_632, - skein1024_640, - skein1024_648, - skein1024_656, - skein1024_664, - skein1024_672, - skein1024_680, - skein1024_688, - skein1024_696, - skein1024_704, - skein1024_712, - skein1024_720, - skein1024_728, - skein1024_736, - skein1024_744, - skein1024_752, - skein1024_760, - skein1024_768, - skein1024_776, - skein1024_784, - skein1024_792, - skein1024_800, - skein1024_808, - skein1024_816, - skein1024_824, - skein1024_832, - skein1024_840, - skein1024_848, - skein1024_856, - skein1024_864, - skein1024_872, - skein1024_880, - skein1024_888, - skein1024_896, - skein1024_904, - skein1024_912, - skein1024_920, - skein1024_928, - skein1024_936, - skein1024_944, - skein1024_952, - skein1024_960, - skein1024_968, - skein1024_976, - skein1024_984, - skein1024_992, - skein1024_1000, - skein1024_1008, - skein1024_1016, - skein1024_1024, - xxh_32, - xxh_64, - xxh3_64, - xxh3_128, - poseidon_bls12_381_a2_fc1, - poseidon_bls12_381_a2_fc1_sc, - rdfc_1, - ssz, - ssz_sha2_256_bmt, - sha2_256_chunked, - json_jcs, - iscc, - zeroxcert_imprint_256, - nonstandard_sig, - bcrypt_pbkdf, - es256k, - bls12_381_g1_sig, - bls12_381_g2_sig, - eddsa, - eip_191, - jwk_jcs_pub, - fil_commitment_unsealed, - fil_commitment_sealed, - plaintextv2, - holochain_adr_v0, - holochain_adr_v1, - holochain_key_v0, - holochain_key_v1, - holochain_sig_v0, - holochain_sig_v1, - skynet_ns, - arweave_ns, - subspace_ns, - kumandra_ns, - es256, - es284, - es512, - rs256, - es256k_msig, - bls12_381_g1_msig, - bls12_381_g2_msig, - eddsa_msig, - bls12_381_g1_share_msig, - bls12_381_g2_share_msig, - lamport_msig, - lamport_share_msig, - es256_msig, - es384_msig, - es521_msig, - rs256_msig, - scion, -}; - -pub const MultiCodeCode = enum(u32) { +pub const Codec = enum(u32) { identity = 0x00, cidv1 = 0x01, cidv2 = 0x02,