1 /** 2 * KeyedFilter 3 * 4 * Copyright: 5 * (C) 1999-2007 Jack Lloyd 6 * (C) 2014-2015 Etienne Cimon 7 * 8 * License: 9 * Botan is released under the Simplified BSD License (see LICENSE.md) 10 */ 11 module botan.filters.key_filt; 12 public import botan.filters.filter; 13 import botan.algo_base.sym_algo; 14 /** 15 * This class represents keyed filters, i.e. filters that have to be 16 * fed with a key in order to function. 17 */ 18 abstract class KeyedFilter : Filter 19 { 20 public: 21 /** 22 * Set the key of this filter 23 * Params: 24 * key = the key to use 25 */ 26 abstract void setKey(in SymmetricKey key); 27 28 /** 29 * Set the initialization vector of this filter. Note: you should 30 * call setIv() only after you have called setKey() 31 * Params: 32 * iv = the initialization vector to use 33 */ 34 void setIv(in InitializationVector iv) 35 { 36 if (iv.length != 0) 37 throw new InvalidIVLength(name(), iv.length); 38 } 39 40 /** 41 * Check whether a key length is valid for this filter 42 * Params: 43 * length = the key length to be checked for validity 44 * Returns: true if the key length is valid, false otherwise 45 */ 46 bool validKeylength(size_t length) const 47 { 48 return keySpec().validKeylength(length); 49 } 50 51 /** 52 * Returns: object describing limits on key size 53 */ 54 abstract KeyLengthSpecification keySpec() const; 55 56 /** 57 * Check whether an IV length is valid for this filter 58 * Params: 59 * length = the IV length to be checked for validity 60 * Returns: true if the IV length is valid, false otherwise 61 */ 62 abstract bool validIvLength(size_t length) const; 63 }