• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "byte_buffer_data_source.h"
16 #include "digest_common.h"
17 
18 namespace OHOS {
19 namespace SignatureTools {
20 
ByteBufferDataSource(class ByteBuffer & hapBuffer)21 ByteBufferDataSource::ByteBufferDataSource(class ByteBuffer& hapBuffer)
22     : DataSource(), bytebuffer(hapBuffer)
23 {
24 }
25 
~ByteBufferDataSource()26 ByteBufferDataSource::~ByteBufferDataSource()
27 {
28 }
29 
HasRemaining() const30 bool ByteBufferDataSource::HasRemaining() const
31 {
32     return bytebuffer.HasRemaining();
33 }
34 
Remaining() const35 int64_t ByteBufferDataSource::Remaining() const
36 {
37     return static_cast<int64_t>(bytebuffer.Remaining());
38 }
39 
Reset()40 void ByteBufferDataSource::Reset()
41 {
42     bytebuffer.Clear();
43 }
44 
ReadDataAndDigestUpdate(const DigestParameter & digestParam,int32_t chunkSize)45 bool ByteBufferDataSource::ReadDataAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize)
46 {
47     const unsigned char* chunk = reinterpret_cast<const unsigned char*>(bytebuffer.GetBufferPtr() +
48                                                                         bytebuffer.GetPosition());
49     bool res = DigestCommon::DigestUpdate(digestParam, chunk, chunkSize);
50     if (res) {
51         bytebuffer.SetPosition(bytebuffer.GetPosition() + chunkSize);
52     }
53     return res;
54 }
55 
56 } // namespace SignatureTools
57 } // namespace OHOS