📄 filters.h
字号:
bool IsolatedFlush(bool hardFlush, bool blocking); void SetFilter(Filter *filter); void NextPutMultiple(const byte *s, size_t len); void NextPutModifiable(byte *inString, size_t length);protected: member_ptr<BufferedTransformation> m_filter;};//! simple proxy filter that doesn't modify the underlying filter's input or outputclass CRYPTOPP_DLL SimpleProxyFilter : public ProxyFilter{public: SimpleProxyFilter(BufferedTransformation *filter, BufferedTransformation *attachment) : ProxyFilter(filter, 0, 0, attachment) {} void FirstPut(const byte *) {} void LastPut(const byte *, size_t) {m_filter->MessageEnd();}};//! proxy for the filter created by PK_Encryptor::CreateEncryptionFilter/*! This class is here just to provide symmetry with VerifierFilter. */class CRYPTOPP_DLL PK_EncryptorFilter : public SimpleProxyFilter{public: PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment = NULL) : SimpleProxyFilter(encryptor.CreateEncryptionFilter(rng), attachment) {}};//! proxy for the filter created by PK_Decryptor::CreateDecryptionFilter/*! This class is here just to provide symmetry with SignerFilter. */class CRYPTOPP_DLL PK_DecryptorFilter : public SimpleProxyFilter{public: PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment = NULL) : SimpleProxyFilter(decryptor.CreateDecryptionFilter(rng), attachment) {}};//! Append input to a string objecttemplate <class T>class StringSinkTemplate : public Bufferless<Sink>{public: // VC60 workaround: no T::char_type typedef typename T::traits_type::char_type char_type; StringSinkTemplate(T &output) : m_output(&output) {assert(sizeof(output[0])==1);} void IsolatedInitialize(const NameValuePairs ¶meters) {if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");} size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking) { if (length > 0) { typename T::size_type size = m_output->size(); if (length < size && size + length > m_output->capacity()) m_output->reserve(2*size); m_output->append((const char_type *)begin, (const char_type *)begin+length); } return 0; }private: T *m_output;};//! Append input to an std::stringCRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate<std::string>;typedef StringSinkTemplate<std::string> StringSink;//! incorporates input into RNG as additional entropyclass RandomNumberSink : public Bufferless<Sink>{public: RandomNumberSink() : m_rng(NULL) {} RandomNumberSink(RandomNumberGenerator &rng) : m_rng(&rng) {} void IsolatedInitialize(const NameValuePairs ¶meters); size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);private: RandomNumberGenerator *m_rng;};//! Copy input to a memory bufferclass CRYPTOPP_DLL ArraySink : public Bufferless<Sink>{public: ArraySink(const NameValuePairs ¶meters = g_nullNameValuePairs) {IsolatedInitialize(parameters);} ArraySink(byte *buf, size_t size) : m_buf(buf), m_size(size), m_total(0) {} size_t AvailableSize() {return SaturatingSubtract(m_size, m_total);} lword TotalPutLength() {return m_total;} void IsolatedInitialize(const NameValuePairs ¶meters); byte * CreatePutSpace(size_t &size); size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);protected: byte *m_buf; size_t m_size; lword m_total;};//! Xor input to a memory bufferclass CRYPTOPP_DLL ArrayXorSink : public ArraySink{public: ArrayXorSink(byte *buf, size_t size) : ArraySink(buf, size) {} size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking); byte * CreatePutSpace(size_t &size) {return BufferedTransformation::CreatePutSpace(size);}};//! string-based implementation of Store interfaceclass StringStore : public Store{public: StringStore(const char *string = NULL) {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} StringStore(const byte *string, size_t length) {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));} template <class T> StringStore(const T &string) {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} CRYPTOPP_DLL size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); CRYPTOPP_DLL size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;private: CRYPTOPP_DLL void StoreInitialize(const NameValuePairs ¶meters); const byte *m_store; size_t m_length, m_count;};//! RNG-based implementation of Source interfaceclass CRYPTOPP_DLL RandomNumberStore : public Store{public: RandomNumberStore() : m_rng(NULL), m_length(0), m_count(0) {} RandomNumberStore(RandomNumberGenerator &rng, lword length) : m_rng(&rng), m_length(length), m_count(0) {} bool AnyRetrievable() const {return MaxRetrievable() != 0;} lword MaxRetrievable() const {return m_length-m_count;} size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const { throw NotImplemented("RandomNumberStore: CopyRangeTo2() is not supported by this store"); }private: void StoreInitialize(const NameValuePairs ¶meters); RandomNumberGenerator *m_rng; lword m_length, m_count;};//! empty storeclass CRYPTOPP_DLL NullStore : public Store{public: NullStore(lword size = ULONG_MAX) : m_size(size) {} void StoreInitialize(const NameValuePairs ¶meters) {} lword MaxRetrievable() const {return m_size;} size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;private: lword m_size;};//! A Filter that pumps data into its attachment as inputclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Source : public InputRejecting<Filter>{public: Source(BufferedTransformation *attachment = NULL) {Source::Detach(attachment);} lword Pump(lword pumpMax=size_t(0)-1) {Pump2(pumpMax); return pumpMax;} unsigned int PumpMessages(unsigned int count=UINT_MAX) {PumpMessages2(count); return count;} void PumpAll() {PumpAll2();} virtual size_t Pump2(lword &byteCount, bool blocking=true) =0; virtual size_t PumpMessages2(unsigned int &messageCount, bool blocking=true) =0; virtual size_t PumpAll2(bool blocking=true); virtual bool SourceExhausted() const =0;protected: void SourceInitialize(bool pumpAll, const NameValuePairs ¶meters) { IsolatedInitialize(parameters); if (pumpAll) PumpAll(); }};//! Turn a Store into a Sourcetemplate <class T>class SourceTemplate : public Source{public: SourceTemplate<T>(BufferedTransformation *attachment) : Source(attachment) {} void IsolatedInitialize(const NameValuePairs ¶meters) {m_store.IsolatedInitialize(parameters);} size_t Pump2(lword &byteCount, bool blocking=true) {return m_store.TransferTo2(*AttachedTransformation(), byteCount, DEFAULT_CHANNEL, blocking);} size_t PumpMessages2(unsigned int &messageCount, bool blocking=true) {return m_store.TransferMessagesTo2(*AttachedTransformation(), messageCount, DEFAULT_CHANNEL, blocking);} size_t PumpAll2(bool blocking=true) {return m_store.TransferAllTo2(*AttachedTransformation(), DEFAULT_CHANNEL, blocking);} bool SourceExhausted() const {return !m_store.AnyRetrievable() && !m_store.AnyMessages();} void SetAutoSignalPropagation(int propagation) {m_store.SetAutoSignalPropagation(propagation);} int GetAutoSignalPropagation() const {return m_store.GetAutoSignalPropagation();}protected: T m_store;};//! string-based implementation of Source interfaceclass CRYPTOPP_DLL StringSource : public SourceTemplate<StringStore>{public: StringSource(BufferedTransformation *attachment = NULL) : SourceTemplate<StringStore>(attachment) {} //! zero terminated string as source StringSource(const char *string, bool pumpAll, BufferedTransformation *attachment = NULL) : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));} //! binary byte array as source StringSource(const byte *string, size_t length, bool pumpAll, BufferedTransformation *attachment = NULL) : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));} //! std::string as source StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment = NULL) : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}};//! use the third constructor for an array sourcetypedef StringSource ArraySource;//! RNG-based implementation of Source interfaceclass CRYPTOPP_DLL RandomNumberSource : public SourceTemplate<RandomNumberStore>{public: RandomNumberSource(RandomNumberGenerator &rng, int length, bool pumpAll, BufferedTransformation *attachment = NULL) : SourceTemplate<RandomNumberStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("RandomNumberGeneratorPointer", &rng)("RandomNumberStoreSize", length));}};NAMESPACE_END#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -