diff options
author | lloyd <[email protected]> | 2012-01-26 21:00:01 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-01-26 21:00:01 +0000 |
commit | 4b8786ad157e38b4143b0968c1ea1c83c2ee7388 (patch) | |
tree | 2a0272f0b6f5e14d738c5bfdb126f5e3ef45fb3b /src/tls/tls_alert.cpp | |
parent | 4b285bd51a48f78f41a14beb9626a8db59e65960 (diff) |
Make Alert a first class object ala Version. Move the alert codes into
the Alert class for namespacing.
Diffstat (limited to 'src/tls/tls_alert.cpp')
-rw-r--r-- | src/tls/tls_alert.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/tls/tls_alert.cpp b/src/tls/tls_alert.cpp new file mode 100644 index 000000000..63cac9d79 --- /dev/null +++ b/src/tls/tls_alert.cpp @@ -0,0 +1,46 @@ +/* +* Alert Message +* (C) 2004-2006,2011 Jack Lloyd +* +* Released under the terms of the Botan license +*/ + +#include <botan/tls_alert.h> +#include <botan/exceptn.h> + +namespace Botan { + +namespace TLS { + +Alert::Alert(const MemoryRegion<byte>& buf) + { + if(buf.size() != 2) + throw Decoding_Error("Alert: Bad size " + to_string(buf.size()) + + " for alert message"); + + if(buf[0] == 1) fatal = false; + else if(buf[0] == 2) fatal = true; + else + throw Decoding_Error("Alert: Bad code for alert level"); + + const byte dc = buf[1]; + + /* + * This is allowed by the specification but is not allocated and we're + * using it internally as a special 'no alert' type. + */ + if(dc == 255) + throw Decoding_Error("Alert: description code 255, rejecting"); + + type_code = static_cast<Type>(dc); + } + +std::string Alert::type_string() const + { + return ""; + } + + +} + +} |