1

This is from RFC 3749 (Transport Layer Security Protocol Compression Methods):

  1. Compression Methods

    TLS [2] includes the following compression method structure in sections 6.1 and 7.4.1.2 and Appendix sections A.4.1 and A.6:

    enum { null(0), (255) } CompressionMethod;
    

I'm not really familiar with C, but I know enough to mark it as resemblant of C enum. What I can't understand though, are the null(0) and (255) parts. I can't seem to find anywhere what parentheses and null would mean in this context.

(I seems hard to even come up with a (Google?) search pattern that would consist of something less ubiquitous than "rfc", "null", "c", "parentheses" and would lead me to other places than questions on "null function pointer" or the most fundamental basics.)

So what do these notations mean syntactically?

  • Why is 255 in parentheses?

  • Why null looks like a function call?

Is this even supposed to be C? Or is it a common notation shared across RFCs? And if it's C, is it specific to enum?

How is this different from enum { 0, 255 } CompressionMethod; or enum { NULL, 255 } CompressionMethod;?

4

3 回答 3

4

你可能在这里有点过度推理:)

您应该引用引用后的行:

which allows for later specification of up to 256 different
compression methods.

这已经解释了这条线的含义。现在,如果您遵循[2]参考列表,您会注意到它指的是RFC 2246。该文件包含以下段落:

4. Presentation language

This document deals with the formatting of data in an external   
representation. The following very basic and somewhat casually   
defined presentation syntax will be used. The syntax draws from   
several sources in its structure. Although it resembles the   
programming language "C" in its syntax and XDR [XDR] in both its   
syntax and intent, it would be risky to draw too many parallels. The  
purpose of this presentation language is to document TLS only, not to 
have general application beyond that particular goal.

因此,该 RFC 的作者似乎从熟悉的元素中炮制了一种简单的语法来简化 RFC 主题的表示,即 TLS。对于枚举,它们指定 4.5 中使用的语言:

4.5. Enumerateds

   An additional sparse data type is available called enum. A field of
   type enum can only assume the values declared in the definition.
   Each definition is a different type. Only enumerateds of the same
   type may be assigned or compared. Every element of an enumerated must
   be assigned a value, as demonstrated in the following example.  Since
   the elements of the enumerated are not ordered, they can be assigned
   any unique value, in any order.

       enum { e1(v1), e2(v2), ... , en(vn) [[, (n)]] } Te;

   Enumerateds occupy as much space in the byte stream as would its
   maximal defined ordinal value. The following definition would cause
   one byte to be used to carry fields of type Color.

       enum { red(3), blue(5), white(7) } Color;

   One may optionally specify a value without its associated tag to
   force the width definition without defining a superfluous element.
   In the following example, Taste will consume two bytes in the data
   stream but can only assume the values 1, 2 or 4.

       enum { sweet(1), sour(2), bitter(4), (32000) } Taste;

   The names of the elements of an enumeration are scoped within the
   defined type. In the first example, a fully qualified reference to
   the second element of the enumeration would be Color.blue. Such
   qualification is not required if the target of the assignment is well
   specified.

       Color color = Color.blue;     /* overspecified, legal */
       Color color = blue;           /* correct, type implicit */

   For enumerateds that are never converted to external representation,
   the numerical information may be omitted.

       enum { low, medium, high } Amount;
于 2013-10-17T12:17:03.160 回答
0

它的意思是CompressionMethod.null具有值0,然后保留255 插槽:

which allows for later specification of up to 256 different

压缩方法

于 2013-10-17T12:17:37.803 回答
0

(255)通知您该字段的大小。因此,对于编码,您知道需要多少字节。如果是,(400)您将需要 2 个字节来指定 0compressionMethod.null0x00 + 0x00。因为 255 可以表示为 1 个字节,您只需要0x00.

本质上,它让您知道枚举字段的大小。

于 2016-02-16T07:55:24.440 回答