Botan  1.11.15
Public Member Functions | Static Public Member Functions
Botan::TLS::Signature_Algorithms Class Reference

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Signature_Algorithms:
Botan::TLS::Extension

List of all members.

Public Member Functions

bool empty () const
std::vector< byteserialize () const
 Signature_Algorithms (const std::vector< std::string > &hashes, const std::vector< std::string > &sig_algos)
 Signature_Algorithms (const std::vector< std::pair< std::string, std::string > > &algos)
 Signature_Algorithms (TLS_Data_Reader &reader, u16bit extension_size)
std::vector< std::pair
< std::string, std::string > > 
supported_signature_algorthms () const
Handshake_Extension_Type type () const

Static Public Member Functions

static byte hash_algo_code (const std::string &name)
static std::string hash_algo_name (byte code)
static byte sig_algo_code (const std::string &name)
static std::string sig_algo_name (byte code)
static Handshake_Extension_Type static_type ()

Detailed Description

Signature Algorithms Extension for TLS 1.2 (RFC 5246)

Definition at line 294 of file tls_extensions.h.


Constructor & Destructor Documentation

Botan::TLS::Signature_Algorithms::Signature_Algorithms ( const std::vector< std::string > &  hashes,
const std::vector< std::string > &  sig_algos 
)

Definition at line 510 of file tls_extensions.cpp.

   {
   for(size_t i = 0; i != hashes.size(); ++i)
      for(size_t j = 0; j != sigs.size(); ++j)
         m_supported_algos.push_back(std::make_pair(hashes[i], sigs[j]));
   }
Botan::TLS::Signature_Algorithms::Signature_Algorithms ( const std::vector< std::pair< std::string, std::string > > &  algos) [inline]

Definition at line 321 of file tls_extensions.h.

                                                                                   :
         m_supported_algos(algos) {}

Definition at line 518 of file tls_extensions.cpp.

References Botan::TLS::TLS_Data_Reader::get_byte(), and Botan::TLS::TLS_Data_Reader::get_u16bit().

   {
   u16bit len = reader.get_u16bit();

   if(len + 2 != extension_size)
      throw Decoding_Error("Bad encoding on signature algorithms extension");

   while(len)
      {
      const std::string hash_code = hash_algo_name(reader.get_byte());
      const std::string sig_code = sig_algo_name(reader.get_byte());

      len -= 2;

      // If not something we know, ignore it completely
      if(hash_code == "" || sig_code == "")
         continue;

      m_supported_algos.push_back(std::make_pair(hash_code, sig_code));
      }
   }

Member Function Documentation

bool Botan::TLS::Signature_Algorithms::empty ( ) const [inline, virtual]
Returns:
if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 316 of file tls_extensions.h.

{ return false; }
byte Botan::TLS::Signature_Algorithms::hash_algo_code ( const std::string &  name) [static]

Definition at line 434 of file tls_extensions.cpp.

   {
   if(name == "MD5")
      return 1;

   if(name == "SHA-1")
      return 2;

   if(name == "SHA-224")
      return 3;

   if(name == "SHA-256")
      return 4;

   if(name == "SHA-384")
      return 5;

   if(name == "SHA-512")
      return 6;

   throw Internal_Error("Unknown hash ID " + name + " for signature_algorithms");
   }

Definition at line 411 of file tls_extensions.cpp.

Referenced by Botan::TLS::Certificate_Verify::Certificate_Verify(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

   {
   switch(code)
      {
      case 1:
         return "MD5";
      // code 1 is MD5 - ignore it

      case 2:
         return "SHA-1";
      case 3:
         return "SHA-224";
      case 4:
         return "SHA-256";
      case 5:
         return "SHA-384";
      case 6:
         return "SHA-512";
      default:
         return "";
      }
   }
std::vector< byte > Botan::TLS::Signature_Algorithms::serialize ( ) const [virtual]
Returns:
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 486 of file tls_extensions.cpp.

   {
   std::vector<byte> buf(2);

   for(size_t i = 0; i != m_supported_algos.size(); ++i)
      {
      try
         {
         const byte hash_code = hash_algo_code(m_supported_algos[i].first);
         const byte sig_code = sig_algo_code(m_supported_algos[i].second);

         buf.push_back(hash_code);
         buf.push_back(sig_code);
         }
      catch(...)
         {}
      }

   buf[0] = get_byte<u16bit>(0, buf.size()-2);
   buf[1] = get_byte<u16bit>(1, buf.size()-2);

   return buf;
   }
byte Botan::TLS::Signature_Algorithms::sig_algo_code ( const std::string &  name) [static]

Definition at line 472 of file tls_extensions.cpp.

   {
   if(name == "RSA")
      return 1;

   if(name == "DSA")
      return 2;

   if(name == "ECDSA")
      return 3;

   throw Internal_Error("Unknown sig ID " + name + " for signature_algorithms");
   }
std::string Botan::TLS::Signature_Algorithms::sig_algo_name ( byte  code) [static]

Definition at line 457 of file tls_extensions.cpp.

Referenced by Botan::TLS::Certificate_Verify::Certificate_Verify(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

   {
   switch(code)
      {
      case 1:
         return "RSA";
      case 2:
         return "DSA";
      case 3:
         return "ECDSA";
      default:
         return "";
      }
   }

Definition at line 297 of file tls_extensions.h.

References Botan::TLS::TLSEXT_SIGNATURE_ALGORITHMS.

Referenced by type().

std::vector<std::pair<std::string, std::string> > Botan::TLS::Signature_Algorithms::supported_signature_algorthms ( ) const [inline]

Definition at line 309 of file tls_extensions.h.

         {
         return m_supported_algos;
         }
Returns:
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 300 of file tls_extensions.h.

References static_type().

{ return static_type(); }

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