# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/filemanagement/storage_service/storage_service_aafwk.gni")

## build sm execute bin file
config("storage_daemon_crypto_config") {
  visibility = [ ":*" ]

  include_dirs = [
    "../include",
    "../include/crypto",
    "${storage_service_common_path}/include",
  ]

  cflags = [
    "-g3",
    "-Wall",
  ]
}

ohos_static_library("libsdcrypto") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }

  sources = [
    "src/app_clone_key_manager.cpp",
    "src/base_key.cpp",
    "src/crypto_delay_handler.cpp",
    "src/fbex.cpp",
    "src/fscrypt_key_v1.cpp",
    "src/fscrypt_key_v1_ext.cpp",
    "src/fscrypt_key_v2.cpp",
    "src/huks_master.cpp",
    "src/iam_client.cpp",
    "src/key_backup.cpp",
    "src/key_crypto_utils.cpp",
    "src/key_manager.cpp",
    "src/openssl_crypto.cpp",
  ]

  defines = [
    "STORAGE_LOG_TAG = \"StorageDaemon\"",
    "LOG_DOMAIN = 0xD004301",
    "OPENSSL_SUPPRESS_DEPRECATED",
    "USER_CRYPTO_MIGRATE_KEY",
    "KMSG_LOG",
  ]

  configs = [ ":storage_daemon_crypto_config" ]

  deps = [
    "${storage_daemon_path}:storage_common_utils",
    "${storage_daemon_path}/libfscrypt:libfscryptutils",
  ]

  external_deps = [
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "huks:libhukssdk",
    "init:libbegetutil",
    "ipc:ipc_single",
    "openssl:libcrypto_shared",
    "os_account:os_account_innerkits",
    "samgr:samgr_proxy",
  ]

  if (storage_service_el5_filekey_manager) {
    defines += [ "EL5_FILEKEY_MANAGER" ]
    external_deps += [ "access_token:el5_filekey_manager_sdk" ]
  }

  if (enable_user_auth_framework) {
    defines += [ "USER_AUTH_FRAMEWORK" ]
    external_deps += [ "user_auth_framework:userauth_client" ]
  }

  subsystem_name = "filemanagement"
  part_name = "storage_service"
}