Botan 3.13.0
Crypto and TLS for C&
Botan::TLS::Supported_Point_Formats Class Referencefinal

#include <tls_extensions_12.h>

Inheritance diagram for Botan::TLS::Supported_Point_Formats:
Botan::TLS::Extension

Public Types

enum  ECPointFormat : uint8_t { UNCOMPRESSED = 0 , ANSIX962_COMPRESSED_PRIME = 1 , ANSIX962_COMPRESSED_CHAR2 = 2 }

Public Member Functions

bool empty () const override
virtual bool is_implemented () const
bool prefers_compressed () const
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 Supported_Point_Formats (bool prefer_compressed)
 Supported_Point_Formats (TLS_Data_Reader &reader, uint16_t extension_size)
Extension_Code type () const override

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Supported Point Formats Extension (RFC 4492)

Definition at line 91 of file tls_extensions_12.h.

Member Enumeration Documentation

◆ ECPointFormat

Enumerator
UNCOMPRESSED 
ANSIX962_COMPRESSED_PRIME 
ANSIX962_COMPRESSED_CHAR2 

Definition at line 93 of file tls_extensions_12.h.

93 : uint8_t /* NOLINT(*-use-enum-class) */ {
94 UNCOMPRESSED = 0,
96 ANSIX962_COMPRESSED_CHAR2 = 2, // don't support these curves
97 };

Constructor & Destructor Documentation

◆ Supported_Point_Formats() [1/2]

Botan::TLS::Supported_Point_Formats::Supported_Point_Formats ( bool prefer_compressed)
inlineexplicit

Definition at line 105 of file tls_extensions_12.h.

105: m_prefers_compressed(prefer_compressed) {}

◆ Supported_Point_Formats() [2/2]

Botan::TLS::Supported_Point_Formats::Supported_Point_Formats ( TLS_Data_Reader & reader,
uint16_t extension_size )

Definition at line 45 of file tls_extensions_12.cpp.

45 {
46 const uint8_t len = reader.get_byte();
47
48 if(len + 1 != extension_size) {
49 throw Decoding_Error("Inconsistent length field in supported point formats list");
50 }
51
52 bool includes_uncompressed = false;
53 for(size_t i = 0; i != len; ++i) {
54 const uint8_t format = reader.get_byte();
55
56 if(static_cast<ECPointFormat>(format) == UNCOMPRESSED) {
57 m_prefers_compressed = false;
58 reader.discard_next(len - i - 1);
59 return;
60 } else if(static_cast<ECPointFormat>(format) == ANSIX962_COMPRESSED_PRIME) {
61 m_prefers_compressed = true;
62 std::vector<uint8_t> remaining_formats = reader.get_fixed<uint8_t>(len - i - 1);
63 includes_uncompressed =
64 std::any_of(std::begin(remaining_formats), std::end(remaining_formats), [](uint8_t remaining_format) {
65 return static_cast<ECPointFormat>(remaining_format) == UNCOMPRESSED;
66 });
67 break;
68 }
69
70 // ignore ANSIX962_COMPRESSED_CHAR2, we don't support these curves
71 }
72
73 // RFC 4492 5.1.:
74 // If the Supported Point Formats Extension is indeed sent, it MUST contain the value 0 (uncompressed)
75 // as one of the items in the list of point formats.
76 // Note:
77 // RFC 8422 5.1.2. explicitly requires this check,
78 // but only if the Supported Groups extension was sent.
79 if(!includes_uncompressed) {
80 throw TLS_Exception(Alert::IllegalParameter,
81 "Supported Point Formats Extension must contain the uncompressed point format");
82 }
83}

References ANSIX962_COMPRESSED_PRIME, Botan::TLS::TLS_Data_Reader::discard_next(), Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::TLS_Data_Reader::get_fixed(), and UNCOMPRESSED.

Member Function Documentation

◆ empty()

bool Botan::TLS::Supported_Point_Formats::empty ( ) const
inlineoverridevirtual

Predicate if a TLS extension should be included or not

Returns
true if this extension should be encoded, otherwise false

Implements Botan::TLS::Extension.

Definition at line 109 of file tls_extensions_12.h.

109{ return false; }

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited

Predicate if the extension is known/implemented

Note
this exists primarily to support unknown extension handling and doesn't need to be overridden even in the custom extension case.
Returns
true if this extension is known

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 113 of file tls_extensions.h.

113{ return true; }

◆ prefers_compressed()

bool Botan::TLS::Supported_Point_Formats::prefers_compressed ( ) const
inline

Definition at line 111 of file tls_extensions_12.h.

111{ return m_prefers_compressed; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Supported_Point_Formats::serialize ( Connection_Side whoami) const
overridevirtual

Serialize a TLS extension

Parameters
whoamiwhich peer we are acting as in the protocol
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 36 of file tls_extensions_12.cpp.

36 {
37 // if this extension is sent, it MUST include uncompressed (RFC 4492, section 5.1)
38 if(m_prefers_compressed) {
39 return std::vector<uint8_t>{2, ANSIX962_COMPRESSED_PRIME, UNCOMPRESSED};
40 } else {
41 return std::vector<uint8_t>{1, UNCOMPRESSED};
42 }
43}

References ANSIX962_COMPRESSED_PRIME, and UNCOMPRESSED.

◆ static_type()

Extension_Code Botan::TLS::Supported_Point_Formats::static_type ( )
inlinestatic

Definition at line 99 of file tls_extensions_12.h.

References Botan::TLS::EcPointFormats.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::Supported_Point_Formats::type ( ) const
inlineoverridevirtual

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 101 of file tls_extensions_12.h.

101{ return static_type(); }

References static_type().


The documentation for this class was generated from the following files: