Scopira  20080306
hash.h
1 
2 /*
3  * Copyright (c) 2005 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED__SCOPIRA_TOOL_HASH_H__
15 #define __INCLUDED__SCOPIRA_TOOL_HASH_H__
16 
17 #include <scopira/tool/array.h>
18 #include <scopira/tool/flow.h>
19 #include <scopira/tool/export.h>
20 
21 namespace scopira
22 {
23  namespace tool
24  {
25  class hashoflow;
26 
32  SCOPIRA_EXPORT std::string hexhash(const scopira::tool::basic_array<byte_t> &hash);
33 
38  SCOPIRA_EXPORT std::string close_and_hexhash(hashoflow &o);
39 
40  //this is declared at the bottom of this .h file
41  //std::string hexhash_string(const std::string &s, int type = scopira::tool::hashoflow::sha1_c);
42  }
43 }
44 
51 {
52  public:
53  enum {
54  sha1_c = 1,
55  };
56 
57  public:
59  SCOPIRA_EXPORT hashoflow(int alg = sha1_c);
61  SCOPIRA_EXPORT virtual ~hashoflow();
62 
64  SCOPIRA_EXPORT virtual bool failed(void) const { return dm_impl != 0; }
65 
67  SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
68 
70  SCOPIRA_EXPORT void open(int alg = sha1_c);
72  SCOPIRA_EXPORT void close(void);
74  SCOPIRA_EXPORT void close(scopira::tool::basic_array<byte_t> &hash);
75 
76  private:
77  void *dm_impl;
78 };
79 
80 namespace scopira
81 {
82  namespace tool
83  {
88  SCOPIRA_EXPORT std::string hexhash_string(const std::string &s, int type = scopira::tool::hashoflow::sha1_c);
89  }
90 }
91 
92 #endif
93 
std::string hexhash_string(const std::string &s, int type=scopira::tool::hashoflow::sha1_c)
scopira::tool::byte_t byte_t
Definition: flow.h:73
std::string hexhash(const scopira::tool::basic_array< byte_t > &hash)
Definition: archiveflow.h:20
virtual size_t write(const byte_t *_buf, size_t _size)
writes a few bytes
std::string close_and_hexhash(hashoflow &o)
void open(int alg=sha1_c)
opens a new hashing session, closing any previous one, if any
virtual ~hashoflow()
dtor
virtual bool failed(void) const
in failed state?
Definition: hash.h:64
hashoflow(int alg=sha1_c)
ctor, does an implicit open
Definition: hash.h:50
void close(void)
close the current link, throwing away the hash
Definition: flow.h:159