00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOTAN_BUFFERED_COMPUTATION_H__
00009 #define BOTAN_BUFFERED_COMPUTATION_H__
00010
00011 #include <botan/secmem.h>
00012
00013 namespace Botan {
00014
00015
00016
00017
00018
00019
00020 class BOTAN_DLL BufferedComputation
00021 {
00022 public:
00023
00024
00025
00026
00027 const u32bit OUTPUT_LENGTH;
00028
00029
00030
00031
00032
00033
00034 void update(const byte in[], u32bit length) { add_data(in, length); }
00035
00036
00037
00038
00039
00040 void update(const MemoryRegion<byte>& in) { add_data(in, in.size()); }
00041
00042
00043
00044
00045
00046
00047
00048 void update(const std::string& str)
00049 {
00050 add_data(reinterpret_cast<const byte*>(str.data()), str.size());
00051 }
00052
00053
00054
00055
00056
00057 void update(byte in) { add_data(&in, 1); }
00058
00059
00060
00061
00062
00063
00064
00065 void final(byte out[]) { final_result(out); }
00066
00067
00068
00069
00070
00071
00072 SecureVector<byte> final()
00073 {
00074 SecureVector<byte> output(OUTPUT_LENGTH);
00075 final_result(output);
00076 return output;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086 SecureVector<byte> process(const byte in[], u32bit length)
00087 {
00088 add_data(in, length);
00089 return final();
00090 }
00091
00092
00093
00094
00095
00096
00097
00098 SecureVector<byte> process(const MemoryRegion<byte>& in)
00099 {
00100 add_data(in, in.size());
00101 return final();
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 SecureVector<byte> process(const std::string& in)
00111 {
00112 update(in);
00113 return final();
00114 }
00115
00116
00117
00118
00119 BufferedComputation(u32bit out_len) : OUTPUT_LENGTH(out_len) {}
00120
00121 virtual ~BufferedComputation() {}
00122 private:
00123 BufferedComputation& operator=(const BufferedComputation&);
00124
00125
00126
00127
00128
00129
00130 virtual void add_data(const byte input[], u32bit length) = 0;
00131
00132
00133
00134
00135
00136 virtual void final_result(byte out[]) = 0;
00137 };
00138
00139 }
00140
00141 #endif