Scopira 20080306

hash.h

00001 
00002 /*
00003  *  Copyright (c) 2005    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013  
00014 #ifndef __INCLUDED__SCOPIRA_TOOL_HASH_H__
00015 #define __INCLUDED__SCOPIRA_TOOL_HASH_H__
00016 
00017 #include <scopira/tool/array.h>
00018 #include <scopira/tool/flow.h>
00019 #include <scopira/tool/export.h>
00020 
00021 namespace scopira
00022 {
00023   namespace tool
00024   {
00025     class hashoflow;
00026 
00032     SCOPIRA_EXPORT std::string hexhash(const scopira::tool::basic_array<byte_t> &hash);
00033 
00038     SCOPIRA_EXPORT std::string close_and_hexhash(hashoflow &o);
00039 
00040     //this is declared at the bottom of this .h file
00041     //std::string hexhash_string(const std::string &s, int type = scopira::tool::hashoflow::sha1_c);
00042   }
00043 }
00044 
00050 class scopira::tool::hashoflow : public scopira::tool::oflow_i
00051 {
00052   public:
00053     enum {
00054       sha1_c = 1,
00055     };
00056 
00057   public:
00059     SCOPIRA_EXPORT hashoflow(int alg = sha1_c);
00061     SCOPIRA_EXPORT virtual ~hashoflow();
00062 
00064     SCOPIRA_EXPORT virtual bool failed(void) const { return dm_impl != 0; }
00065 
00067     SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
00068 
00070     SCOPIRA_EXPORT void open(int alg = sha1_c);
00072     SCOPIRA_EXPORT void close(void);
00074     SCOPIRA_EXPORT void close(scopira::tool::basic_array<byte_t> &hash);
00075 
00076   private:
00077     void *dm_impl;
00078 };
00079 
00080 namespace scopira
00081 {
00082   namespace tool
00083   {
00088     SCOPIRA_EXPORT  std::string hexhash_string(const std::string &s, int type = scopira::tool::hashoflow::sha1_c);
00089   }
00090 }
00091 
00092 #endif
00093