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