1 /*-------------------------------------------------------------------------
2  * drawElements C++ Base Library
3  * -----------------------------
4  *
5  * Copyright 2015 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief SHA1 hash functions
22  *//*--------------------------------------------------------------------*/
23 
24 #include "deSha1.hpp"
25 
26 namespace de
27 {
28 
parse(const std::string & str)29 Sha1 Sha1::parse (const std::string& str)
30 {
31 	deSha1 hash;
32 
33 	DE_CHECK_RUNTIME_ERR_MSG(str.size() >= 40, "Failed to parse SHA1. String is too short.");
34 	DE_CHECK_RUNTIME_ERR_MSG(deSha1_parse(&hash, str.c_str()), "Failed to parse SHA1. Invalid characters..");
35 
36 	return Sha1(hash);
37 }
38 
compute(size_t size,const void * data)39 Sha1 Sha1::compute (size_t size, const void* data)
40 {
41 	deSha1 hash;
42 
43 	deSha1_compute(&hash, size, data);
44 	return Sha1(hash);
45 }
46 
Sha1Stream(void)47 Sha1Stream::Sha1Stream (void)
48 {
49 	deSha1Stream_init(&m_stream);
50 }
51 
process(size_t size,const void * data)52 void Sha1Stream::process (size_t size, const void* data)
53 {
54 	deSha1Stream_process(&m_stream, size, data);
55 }
56 
finalize(void)57 Sha1 Sha1Stream::finalize (void)
58 {
59 	deSha1 hash;
60 	deSha1Stream_finalize(&m_stream, &hash);
61 
62 	return Sha1(hash);
63 }
64 
65 } // de
66