Botan  1.11.15
src/lib/tls/tls_version.h
Go to the documentation of this file.
00001 /*
00002 * TLS Protocol Version Management
00003 * (C) 2012 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_TLS_PROTOCOL_VERSION_H__
00009 #define BOTAN_TLS_PROTOCOL_VERSION_H__
00010 
00011 #include <botan/get_byte.h>
00012 #include <string>
00013 
00014 namespace Botan {
00015 
00016 namespace TLS {
00017 
00018 /**
00019 * TLS Protocol Version
00020 */
00021 class BOTAN_DLL Protocol_Version
00022    {
00023    public:
00024       enum Version_Code {
00025          TLS_V10            = 0x0301,
00026          TLS_V11            = 0x0302,
00027          TLS_V12            = 0x0303,
00028 
00029          DTLS_V10           = 0xFEFF,
00030          DTLS_V12           = 0xFEFD
00031       };
00032 
00033       static Protocol_Version latest_tls_version()
00034          {
00035          return Protocol_Version(TLS_V12);
00036          }
00037 
00038       static Protocol_Version latest_dtls_version()
00039          {
00040          return Protocol_Version(DTLS_V12);
00041          }
00042 
00043       Protocol_Version() : m_version(0) {}
00044 
00045       /**
00046       * @param named_version a specific named version of the protocol
00047       */
00048       Protocol_Version(Version_Code named_version) :
00049          m_version(static_cast<u16bit>(named_version)) {}
00050 
00051       /**
00052       * @param major the major version
00053       * @param minor the minor version
00054       */
00055       Protocol_Version(byte major, byte minor) :
00056          m_version((static_cast<u16bit>(major) << 8) | minor) {}
00057 
00058       /**
00059       * @return true if this is a valid protocol version
00060       */
00061       bool valid() const { return (m_version != 0); }
00062 
00063       /**
00064       * @return true if this is a protocol version we know about
00065       */
00066       bool known_version() const;
00067 
00068       /**
00069       * @return major version of the protocol version
00070       */
00071       byte major_version() const { return get_byte(0, m_version); }
00072 
00073       /**
00074       * @return minor version of the protocol version
00075       */
00076       byte minor_version() const { return get_byte(1, m_version); }
00077 
00078       /**
00079       * @return human-readable description of this version
00080       */
00081       std::string to_string() const;
00082 
00083       /**
00084       * @return true iff this is a DTLS version
00085       */
00086       bool is_datagram_protocol() const;
00087 
00088       /**
00089       * @return true if this version supports negotiable signature algorithms
00090       */
00091       bool supports_negotiable_signature_algorithms() const;
00092 
00093       /**
00094       * @return true if this version uses explicit IVs for block ciphers
00095       */
00096       bool supports_explicit_cbc_ivs() const;
00097 
00098       /**
00099       * @return true if this version uses a ciphersuite specific PRF
00100       */
00101       bool supports_ciphersuite_specific_prf() const;
00102 
00103       bool supports_aead_modes() const;
00104 
00105       /**
00106       * @return if this version is equal to other
00107       */
00108       bool operator==(const Protocol_Version& other) const
00109          {
00110          return (m_version == other.m_version);
00111          }
00112 
00113       /**
00114       * @return if this version is not equal to other
00115       */
00116       bool operator!=(const Protocol_Version& other) const
00117          {
00118          return (m_version != other.m_version);
00119          }
00120 
00121       /**
00122       * @return if this version is later than other
00123       */
00124       bool operator>(const Protocol_Version& other) const;
00125 
00126       /**
00127       * @return if this version is later than or equal to other
00128       */
00129       bool operator>=(const Protocol_Version& other) const
00130          {
00131          return (*this == other || *this > other);
00132          }
00133 
00134    private:
00135       u16bit m_version;
00136    };
00137 
00138 }
00139 
00140 }
00141 
00142 #endif
00143