xref: /netbsd-src/external/mpl/bind/dist/contrib/scripts/catzhash.py (revision 4d342c046e3288fb5a1edcd33cfec48c41c80664)
1#!/usr/bin/python
2# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3#
4# This Source Code Form is subject to the terms of the Mozilla Public
5# License, v. 2.0. If a copy of the MPL was not distributed with this
6# file, You can obtain one at http://mozilla.org/MPL/2.0/.
7#
8# See the COPYRIGHT file distributed with this work for additional
9# information regarding copyright ownership.
10
11# catzhash.py: generate the SHA-1 hash of a domain name in wire format.
12#
13# This can be used to determine the label to use in a catalog zone to
14# represent the specified zone. For example, the zone
15# "domain.example" can be represented in a catalog zone called
16# "catalog.example" by adding the following record:
17#
18# 5960775ba382e7a4e09263fc06e7c00569b6a05c.zones.catalog.example. \
19#    IN PTR domain.example.
20#
21# The label "5960775ba382e7a4e09263fc06e7c00569b6a05c" is the output of
22# this script when run with the argument "domain.example".
23
24import sys
25import hashlib
26import dns.name
27
28if len(sys.argv) < 2:
29    print("Usage: %s name" % sys.argv[0])
30
31NAME = dns.name.from_text(sys.argv[1]).to_wire()
32print(hashlib.sha1(NAME).hexdigest())
33