Re: [Cbor] draft-ietf-cbor-network-addresses: tag validity; deterministic encoding

Brian E Carpenter <> Wed, 03 November 2021 04:09 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id 0633B3A0E03 for <>; Tue, 2 Nov 2021 21:09:00 -0700 (PDT)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -5.429
X-Spam-Status: No, score=-5.429 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-3.33, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: (amavisd-new); dkim=pass (2048-bit key)
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id e9Rh-SwDJiOW for <>; Tue, 2 Nov 2021 21:08:55 -0700 (PDT)
Received: from ( [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 2142B3A0E02 for <>; Tue, 2 Nov 2021 21:08:55 -0700 (PDT)
Received: by with SMTP id y4so1048913pfa.5 for <>; Tue, 02 Nov 2021 21:08:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Z4cL8NQEarfJ4BJV2K6hcFFpPi3XDaKacRz4pcn678w=; b=qk2lo04PYB3Sii8FslKh5kW8HycYVBqgzvVEub1rRFVzG3olWzK23SWbJWV5UTp2JD Xx5LdJ8zIL5I8rg7SoiWPlYWjBytVCnd/cBgDP1vDlRPbfJJJREi5zLvhP6Gi6u2R7sZ c6vtSCyfO7LAyuJwiEv4/iycUbWa0zKm9HeQVuIjpI0QpQr1QEW0od/HDj8k2O91vrFN 1NDnn60doII1c/3uMc3gDOsAs9ztX0PLm9L0Y6T7tzFu4Y7VMLF3qAw6BNx14B+Wrqvc Z0e+jFQH7a88FEpNHl8k2OpVdeHCQlebzMGheAPZvKsb5zcil6ihIR/2hnTM4M5hEsfZ 0cYA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Z4cL8NQEarfJ4BJV2K6hcFFpPi3XDaKacRz4pcn678w=; b=2FIBkGgTQ7wtQaI6bKnb04WY42xAGY2AmB92m/c4zt9tzfGcifE1Im6dT/S/U4NsbO 3AKi7jaDRZnfwxZ/NW75IO58dtX75EpdAqo2DC24bKMOZBGdDMyVcqiUUXh45G/ALs6X Hbe8WJYXVgAEZzLtcAwuBIfeVXcrK3tI8gVqIgVdIniFLsz+BTc5JoR0ppo/ON6OrUrr HeQvV7q7n6wvSom70VgWkfHNjg0521aDvM6WhqT3wDCt5fLcSrm7PEpAYEkzb8PAZZ3e jQrXkXy86B5L2pjknNcz/TxD5/J2fVNi4DfKKBd/9earyXrtxlicuLexc+tF786cdYdd BltQ==
X-Gm-Message-State: AOAM530MT+wgfeDZuV9fH8lpdM1oNk69DJjWt3wuNUYy9gTlMbkjkdLW 3VaZMtkx7KLGKOUgrEwUVGc=
X-Google-Smtp-Source: ABdhPJx0QjvPY6TFXHuTC3aT+XTsoqO96rfjhai9buaU/cx7/MdXTQRqlelZxkl03eprek06wrAHKA==
X-Received: by 2002:a63:8ac3:: with SMTP id y186mr18978190pgd.444.1635912532986; Tue, 02 Nov 2021 21:08:52 -0700 (PDT)
Received: from ?IPv6:2406:e003:102d:e801:80b2:5c79:2266:e431? ([2406:e003:102d:e801:80b2:5c79:2266:e431]) by with ESMTPSA id l14sm3919246pjq.13.2021. (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Nov 2021 21:08:02 -0700 (PDT)
To: Carsten Bormann <>
Cc:, Michael Richardson <>
References: <> <> <> <> <>
From: Brian E Carpenter <>
Message-ID: <>
Date: Wed, 3 Nov 2021 17:07:46 +1300
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable
Archived-At: <>
Subject: Re: [Cbor] draft-ietf-cbor-network-addresses: tag validity; deterministic encoding
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-Subscribe: <>, <>
X-List-Received-Date: Wed, 03 Nov 2021 04:09:00 -0000

On 15-Oct-21 17:50, Carsten Bormann wrote:
> On 15. Oct 2021, at 06:35, Brian E Carpenter <> wrote:
>> So, my ugly code is in the functions build5254() and detag5254() in
> Nice.
> After line 122, there needs to be the Python equivalent of a
> prefix.sub!(/\x00*\z/, ‘’)

I took an executive decision to throw an exception for covert bits, rather than silently zero them, and in fact changed all my error returns to ValueError exceptions. I believe that's more Pythonesque.
> (Why not mix floating point calculations and a regex in the same five lines of code :-)

Because it makes my head hurt, that's why not.
> Before line 146, you’d need to check whether the size really is 

Yes, or that the type really is 'bytes' since Python won't check that for 

> I think the while loop in 154 needs to be before 151.

I don't think it matters. Either way, the zero bytes get concatenated.
> If v[0] == 128 and prefix is 16 bytes, what does prefix[v[0]//8] yield in Python?

IndexError: index out of range

Good catch. In my app, that is a case that would never happen.

I've fixed my code, but will let my test app run for a few hours before I 
post the update to github.