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

Brian E Carpenter <brian.e.carpenter@gmail.com> Wed, 03 November 2021 04:09 UTC

Return-Path: <brian.e.carpenter@gmail.com>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0633B3A0E03 for <cbor@ietfa.amsl.com>; Tue, 2 Nov 2021 21:09:00 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -5.429
X-Spam-Level:
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: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id e9Rh-SwDJiOW for <cbor@ietfa.amsl.com>; Tue, 2 Nov 2021 21:08:55 -0700 (PDT)
Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2142B3A0E02 for <cbor@ietf.org>; Tue, 2 Nov 2021 21:08:55 -0700 (PDT)
Received: by mail-pf1-x436.google.com with SMTP id y4so1048913pfa.5 for <cbor@ietf.org>; Tue, 02 Nov 2021 21:08:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; 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; d=1e100.net; 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 smtp.gmail.com with ESMTPSA id l14sm3919246pjq.13.2021.11.02.21.07.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Nov 2021 21:08:02 -0700 (PDT)
To: Carsten Bormann <cabo@tzi.org>
Cc: cbor@ietf.org, Michael Richardson <mcr+ietf@sandelman.ca>
References: <891995AA-2854-431E-9242-98FFCDA5E161@tzi.org> <dab25fe3-43c4-865e-2c7a-54b24340c295@gmail.com> <19BCDB95-AB61-4F92-A38D-F6FD5CA8BBB1@tzi.org> <a616b11c-0fc3-436b-96b0-12a6156c37f5@gmail.com> <DAE0122E-D6AB-45B2-A287-AC270AD8A7CD@tzi.org>
From: Brian E Carpenter <brian.e.carpenter@gmail.com>
Message-ID: <d94b9b9b-1165-9f4d-2a55-1ed98fd8142b@gmail.com>
Date: Wed, 03 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: <DAE0122E-D6AB-45B2-A287-AC270AD8A7CD@tzi.org>
Content-Type: text/plain; charset="utf-8"; format="flowed"
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/Vw2yK1RYPVZyL9G133JOnCe6rdc>
Subject: Re: [Cbor] draft-ietf-cbor-network-addresses: tag validity; deterministic encoding
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=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 <brian.e.carpenter@gmail.com> wrote:
>>
>> So, my ugly code is in the functions build5254() and detag5254() in https://github.com/becarpenter/graspy/blob/master/pfxm4.py
> 
> 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 
`asize`.

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

> 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.

    Brian