Re: [Cbor] dCBOR moving from numerically-typeless systems

Wolf McNally <wolf@wolfmcnally.com> Sun, 12 March 2023 11:49 UTC

Return-Path: <wolf@wolfmcnally.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 01A75C14CE2B for <cbor@ietfa.amsl.com>; Sun, 12 Mar 2023 04:49:32 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.872
X-Spam-Level:
X-Spam-Status: No, score=-0.872 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, MISSING_HEADERS=1.021, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=no autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=wolfmcnally-com.20210112.gappssmtp.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oE2xkAPsHc39 for <cbor@ietfa.amsl.com>; Sun, 12 Mar 2023 04:49:27 -0700 (PDT)
Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id CADA4C14CF13 for <cbor@ietf.org>; Sun, 12 Mar 2023 04:49:27 -0700 (PDT)
Received: by mail-oi1-x22f.google.com with SMTP id bm20so7607152oib.7 for <cbor@ietf.org>; Sun, 12 Mar 2023 04:49:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfmcnally-com.20210112.gappssmtp.com; s=20210112; t=1678621766; h=message-id:references:cc:in-reply-to:date:subject:mime-version:from :from:to:cc:subject:date:message-id:reply-to; bh=0py/oJy5dLst4iRfFcJ0lJUr69dsxWwoUkyPe2H3Ldg=; b=wIz9MIvS4AFJL53kPd7bA8YyHpzGeq0daiD1WMZt3StcJ19SfBgw8mYTim51U1O/ud BHpXWlGQsz0edn4BU5eAG8YpSqF3DXIWWrPaos6FiUPa0kavC4Rop7pSp182tQvb4i8d 7GUd3HYQoKGZX5omj6W118Jv22/jPk1Ybj6qVI5wCKreT2wB/AN4HkRLGuqx7TzoOpvU OBTbPFR2dVHMvQ8J2eQ+aAp5DW+RyX256OFVaNA4MWm5DWO1KkUFDC6TqugQmHqO0btx vtOISnitC4hSuKuwStUZj7qImZJbn2uN0gWvtPsBEbW5B9fwneNhdxju/J4N4alt8N2Z PbDg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678621766; h=message-id:references:cc:in-reply-to:date:subject:mime-version:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0py/oJy5dLst4iRfFcJ0lJUr69dsxWwoUkyPe2H3Ldg=; b=DWUEV0obwwdNAojkMaalPZ5sZg5c+frU+UlEf5Hpdz/19S5VOXHwdPyFWtO1SYTMqq PjwMHlZi+esNBcNF9XFhxa3IJCzPIEVdc4DynONl20bHF5oF0Vyag0szIntVvnQW4vyJ Qq1xjWePNfH+G5BE/UyuRDGwV5rrhcrRMa06kqBJ7pyBVglsqVZH0J3GWmIgbeXuBTHG OhjezvWTYVGE6gaE16mKqIiqrZLQ7luVPWLEdGSyNw/5KOGi0oZxqnu4UtneMz4WoNOi /KmCkQN58n0LswironX2k4zPyhFsoZfU4f0O5Pj0fh5jq2w4kBYiQMGESWw31hO4WfYu BTnw==
X-Gm-Message-State: AO0yUKXeme95GZ1a/q48w2fchsGjAqrogVsHFFgvpcGS2JSXpI6bSiAZ kL+8uTGDO75z4FUqc4L4iUaNDvjwQLIQcN2QTIU=
X-Google-Smtp-Source: AK7set+6ZKx9ivejU97y2jzT45k9h/2wPAdruRdHHwAC/68r1HstF8xSAwqJSyRAnpqU8uSOllbtHQ==
X-Received: by 2002:aca:220a:0:b0:384:8b17:3796 with SMTP id b10-20020aca220a000000b003848b173796mr13454701oic.11.1678621766023; Sun, 12 Mar 2023 04:49:26 -0700 (PDT)
Received: from smtpclient.apple ([185.222.243.89]) by smtp.gmail.com with ESMTPSA id y13-20020a4ade0d000000b005251903c669sm2063662oot.13.2023.03.12.04.49.25 for <cbor@ietf.org> (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Mar 2023 04:49:25 -0700 (PDT)
From: Wolf McNally <wolf@wolfmcnally.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_A16D8B35-60D9-4CA8-8E51-1D8CCD64CD30"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\))
Date: Sun, 12 Mar 2023 04:49:14 -0700
In-Reply-To: <D714A0A4-7452-4C45-8542-7A57A75C9748@tzi.org>
Cc: cbor@ietf.org
References: <2B1FA8CC-AD83-4E58-BE27-B6504F555694@wolfmcnally.com> <8551021E-A1A2-4764-B0DF-D3E7591EC9B6@tzi.org> <FD5D8771-E1CF-4C63-A141-054DE0085399@wolfmcnally.com> <D714A0A4-7452-4C45-8542-7A57A75C9748@tzi.org>
Message-Id: <35A71381-A9DD-479C-A7D5-9B06F70B6F50@wolfmcnally.com>
X-Mailer: Apple Mail (2.3731.400.51.1.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/u5JZvvb40QMwt91bjVVuWRomLqA>
Subject: Re: [Cbor] dCBOR moving from numerically-typeless systems
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
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: Sun, 12 Mar 2023 11:49:32 -0000

Carsten,

> On Mar 12, 2023, at 3:26 AM, Carsten Bormann <cabo@tzi.org <mailto:cabo@tzi.org>> wrote:
> ...maybe you can explain your “no `null` in map entry values” rule next.  Isn’t that really very much about how the application processes these values?

Just like numeric values have multiple equivalent CBOR representations, map entries with “no value” also have two semantically-equivalent representations:

• omit the entry entirely, or
• encode the entry, but give it a `null` value.

If these representations are semantically equivalent, then like numeric values, this calls for reduction to a canonical case because we don’t want disparate agents making different choices about how to encode the same semantics.

Hypothetically, the protocol specification for a map could have hundreds of possible documented keys, most or all of which are optional. If we are to represent this optionality deterministically, we have two choices:

• include possibly hundreds of keys, many with a `null` value, or
• only include keys with non-`null` values.

As I said, it is not a choice to let the protocol adopter decide, as this breaks determinism. Should we let the protocol specifier decide? This would require a compelling case that there could be a meaningful difference in semantics between a `null`-valued map entry and the omission of the entry, and I have yet to see such an argument.

Even having ruled out null-valued map entries, this still leaves protocol specifiers with a choice about the semantics of an omitted entry. I deal with this in section 4.1 of the I-D:

> Protocols that depend on dCBOR MUST specify the circumstances under which particular optional fields MUST or MUST NOT be present. Protocols that specify fields using key-value paired structures like CBOR maps, where some fields have default values MUST choose and document one of the following strategies:
> 
> • they MUST specify that the absence of the field means choosing the default. This allows the default to be changed later, or
> • they MUST encode the field regardless of whether the current default is chosen. This locks in the current value of the default.

https://blockchaincommons.github.io/WIPs-IETF-draft-deterministic-cbor/draft-mcnally-deterministic-cbor.html#name-optional-default-values

Neither of the above choices requires a `null`-valued map entry.

So there is definitely a responsibility of the specifier to determine how the absence of an optional key is processed.

Again: the principle is that as much cognitive burden as possible should be placed on the codec. Obviously, the codec can only reject cases as invalid that it can detect. Since the codec can mechanically detect the presence of a key with a `null` value, and since there exists an equivalent way of representing the same semantics (the absence of the key), we therefore specify that the absence of the key is canonical and that the codec MUST reject the case it can detect: a `null`-valued entry.

After the codec validates a map, then it is again up to the application developer to perform any additional validations, such as whether all required keys are present, whether the combination of optional keys present is valid, that no additional unsupported keys are present, and whether all present keys have values in their allowable ranges.

~ Wolf