• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
16 #include "cf_check.h"
17 
18 #include "cf_log.h"
19 #include "cf_result.h"
20 
CfCheckBlob(const CfBlob * blob,uint32_t maxLen)21 int32_t CfCheckBlob(const CfBlob *blob, uint32_t maxLen)
22 {
23     if ((blob == NULL) || (blob->data == NULL) || (blob->size == 0) || (blob->size > maxLen)) {
24         CF_LOG_E("invalid input params");
25         return CF_INVALID_PARAMS;
26     }
27     return CF_SUCCESS;
28 }
29 
CfCheckEncodingBlob(const CfEncodingBlob * blob,uint32_t maxLen)30 int32_t CfCheckEncodingBlob(const CfEncodingBlob *blob, uint32_t maxLen)
31 {
32     if ((blob == NULL) || (blob->data == NULL) || (blob->len == 0) || (blob->len > maxLen)) {
33         CF_LOG_E("invalid input params");
34         return CF_INVALID_PARAMS;
35     }
36 
37     if ((blob->encodingFormat != CF_FORMAT_DER) && (blob->encodingFormat != CF_FORMAT_PEM)) {
38         CF_LOG_E("invalid encode format");
39         return CF_ERR_INVALID_CODE_FORMAT;
40     }
41     return CF_SUCCESS;
42 }
43