bd3fc11a17b51e74fe6be8ac83f50b59340995f3
[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 <safe-buffer.h>
20 #include <dpl/noncopyable.h>
21 #include <dpl/exception.h>
22 #include <ckm/ckm-type.h>
23
24 /*
25  * Taken from openssl/ossl_typ.h
26  */
27 struct env_md_ctx_st;
28 typedef env_md_ctx_st EVP_MD_CTX;
29 struct env_md_st;
30 typedef env_md_st EVP_MD;
31
32 namespace CKM {
33
34 class Digest : public CKM::Noncopyable
35 {
36     public:
37         class Exception
38         {
39             public:
40                 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
41                 DECLARE_EXCEPTION_TYPE(Base, InternalError)
42         };
43         Digest();
44         ~Digest();
45         void append(const SafeBuffer &data, std::size_t len = 0);
46         SafeBuffer finalize(void);
47         SafeBuffer get(void);
48         void reset(void);
49         unsigned int length(void);
50
51     private:
52         EVP_MD_CTX *m_ctx;
53         const EVP_MD *m_md;
54         SafeBuffer m_digest;
55         bool m_initialized;
56         bool m_finalized;
57 };
58
59 } // namespace CKM
60