summaryrefslogtreecommitdiff
path: root/src/crypto_context.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-01-24 04:15:26 +0100
committerCarl Hetherington <cth@carlh.net>2021-01-24 04:15:26 +0100
commitceaf7bc52712cb60708ed5eb5c62c5e463dd8e89 (patch)
treec55e4b85ee30138ce83263045d77d01631378b2e /src/crypto_context.h
parent6c37cc1979b2a01205a888c4c98f3334685ee8dd (diff)
Tidying.
Diffstat (limited to 'src/crypto_context.h')
-rw-r--r--src/crypto_context.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/crypto_context.h b/src/crypto_context.h
index 263121bf..6020ea88 100644
--- a/src/crypto_context.h
+++ b/src/crypto_context.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -31,9 +31,16 @@
files in the program, then also delete it here.
*/
+
+/** @file src/crypto_context.h
+ * @class CryptoContext class
+ */
+
+
#ifndef LIBDCP_CRYPTO_CONTEXT_H
#define LIBDCP_CRYPTO_CONTEXT_H
+
#include "key.h"
#include "types.h"
#include "exceptions.h"
@@ -41,22 +48,24 @@
#include <asdcp/KM_prng.h>
#include <boost/optional.hpp>
+
namespace dcp {
+
template <class T>
class CryptoContext
{
public:
CryptoContext (boost::optional<Key> key, Standard standard)
- : _context (0)
- , _hmac (0)
+ : _context (nullptr)
+ , _hmac (nullptr)
{
if (!key) {
return;
}
- _context = new T;
- if (ASDCP_FAILURE (_context->InitKey (key->value ()))) {
+ _context = new T ();
+ if (ASDCP_FAILURE (_context->InitKey(key->value()))) {
throw MiscError ("could not set up crypto context");
}
@@ -76,7 +85,7 @@ public:
type = ASDCP::LS_MXF_SMPTE;
}
- if (ASDCP_FAILURE (_hmac->InitKey (key->value(), type))) {
+ if (ASDCP_FAILURE (_hmac->InitKey(key->value(), type))) {
throw MiscError ("could not set up HMAC context");
}
}
@@ -100,9 +109,12 @@ private:
ASDCP::HMACContext* _hmac;
};
+
typedef CryptoContext<ASDCP::AESEncContext> EncryptionContext;
typedef CryptoContext<ASDCP::AESDecContext> DecryptionContext;
+
}
+
#endif