e89032944eb989968883c0c502770d409eddf9a5
[platform/core/security/key-manager.git] / src / manager / common / digest.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #pragma once
18
19 #include <dpl/noncopyable.h>
20 #include <dpl/exception.h>
21 #include <ckm/ckm-type.h>
22
23 /*
24  * Taken from openssl/ossl_typ.h
25  */
26 struct env_md_ctx_st;
27 typedef env_md_ctx_st EVP_MD_CTX;
28 struct env_md_st;
29 typedef env_md_st EVP_MD;
30
31 namespace CKM {
32
33 class Digest : public CKM::Noncopyable
34 {
35     public:
36         class Exception
37         {
38             public:
39                 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
40                 DECLARE_EXCEPTION_TYPE(Base, InternalError)
41         };
42         Digest();
43         ~Digest();
44         void append(const RawBuffer &data, std::size_t len = 0);
45         RawBuffer finalize(void);
46         RawBuffer get(void);
47         void reset(void);
48         unsigned int length(void);
49
50     private:
51         EVP_MD_CTX *m_ctx;
52         const EVP_MD *m_md;
53         RawBuffer m_digest;
54         bool m_initialized;
55         bool m_finalized;
56 };
57
58 } // namespace CKM
59