From 660d985e92d030f4ec0c3503bc14363825183371 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 3 Nov 2016 13:11:18 -0400 Subject: Simplify some code by using T::create_or_throw --- src/lib/tls/tls_cbc/tls_cbc.cpp | 9 ++------- src/lib/tls/tls_handshake_hash.cpp | 6 +----- 2 files changed, 3 insertions(+), 12 deletions(-) (limited to 'src/lib/tls') diff --git a/src/lib/tls/tls_cbc/tls_cbc.cpp b/src/lib/tls/tls_cbc/tls_cbc.cpp index 71ad41114..ef397e44d 100644 --- a/src/lib/tls/tls_cbc/tls_cbc.cpp +++ b/src/lib/tls/tls_cbc/tls_cbc.cpp @@ -33,13 +33,8 @@ TLS_CBC_HMAC_AEAD_Mode::TLS_CBC_HMAC_AEAD_Mode(const std::string& cipher_name, m_mac_keylen(mac_keylen), m_use_encrypt_then_mac(use_encrypt_then_mac) { - m_cipher = BlockCipher::create(m_cipher_name); - if(!m_cipher) - throw Algorithm_Not_Found(m_cipher_name); - - m_mac = MessageAuthenticationCode::create("HMAC(" + m_mac_name + ")"); - if(!m_mac) - throw Algorithm_Not_Found("HMAC(" + m_mac_name + ")"); + m_cipher = BlockCipher::create_or_throw(m_cipher_name); + m_mac = MessageAuthenticationCode::create_or_throw("HMAC(" + m_mac_name + ")"); m_tag_size = m_mac->output_length(); m_block_size = m_cipher->block_size(); diff --git a/src/lib/tls/tls_handshake_hash.cpp b/src/lib/tls/tls_handshake_hash.cpp index 4f78bebbc..540f1de14 100644 --- a/src/lib/tls/tls_handshake_hash.cpp +++ b/src/lib/tls/tls_handshake_hash.cpp @@ -29,11 +29,7 @@ secure_vector Handshake_Hash::final(Protocol_Version version, }; const std::string hash_algo = choose_hash(); - std::unique_ptr hash(HashFunction::create(hash_algo)); - if(!hash) - { - throw Algorithm_Not_Found(hash_algo); - } + std::unique_ptr hash(HashFunction::create_or_throw(hash_algo)); hash->update(m_data); return hash->final(); } -- cgit v1.2.3