2013-10-17 15 views
1

这是从RFC 3749(传输层安全协议压缩方法):这是在TLS RFC中的枚举符号?

  1. 压缩方法

    TLS [2]包括在 第6.1和7.4.1.2和附录下面的压缩方法的结构部分A.4.1和A.6:

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

我对C不是很熟悉,但我足够了解它将其标记为C enum的类似物。我不明白,但是,null(0)(255)部分。在这种情况下,我似乎无法找到任何括号和空值。 (我似乎很难甚至想出一个(Google?)搜索模式,它将包含一些比“rfc”,“null”,“c”,“括号”更普遍的东西,并且会导致我到其他地方比关于“空函数指针”的问题或最基本的基础知识)。

那么这些符号是什么意思在语法上呢?

  • 为什么255在括号内?

  • 为什么null看起来像一个函数调用?

这甚至应该是C?或者它是在RFC中共享的通用符号?如果是C,是否特定于enum

这与enum { 0, 255 } CompressionMethod;enum { NULL, 255 } CompressionMethod;有什么不同?

回答

4

您可以在这里overreasoning有点:)

你应该引述按照你的报价行:

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; 
+0

*你可能在这里有点过度:)*你不是第一个告诉我这个,但问题就像在我的脑窝里饿了小鸡!一个根本无法集中在噪音中......:D –

+0

那么我真诚地希望我的回答至少使这个饥饿的小妞变得沉默:)更重要的是,我还展示了从原始问题到源代码的步骤 - “给男人一个鱼'&东西... – fvu

0

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

which allows for later specification of up to 256 different 

压缩方法

0

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

本质上它可以让你知道枚举字段的大小。