Skip to content

Commit

Permalink
hide some header files that users don't depends on
Browse files Browse the repository at this point in the history
  • Loading branch information
benzfield committed Aug 21, 2023
1 parent ebcacc5 commit cc2142b
Show file tree
Hide file tree
Showing 40 changed files with 546 additions and 159 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

cmake_minimum_required(VERSION 3.14)
project(hsmc VERSION 1.0.0 LANGUAGES CXX)

Expand Down
14 changes: 14 additions & 0 deletions cmake/CLI11.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

find_package(CLI11 CONFIG QUIET)
if (NOT CLI11_FOUND)
set(CLI11_GIT_REPO https://github.com/CLIUtils/CLI11.git)
Expand Down
14 changes: 14 additions & 0 deletions cmake/FindSphinx.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

#Look for an executable called sphinx-build
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
Expand Down
14 changes: 13 additions & 1 deletion cmake/abseil-cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# cmake/yaml-cpp.cmake
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

find_package(absl QUIET)

Expand Down
15 changes: 15 additions & 0 deletions cmake/configuration.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.
#
# defines configuration options
# note: only include it in hsmc's top-level CMakeLists.txt
#
include(CMakeDependentOption)

# what to build
Expand Down
2 changes: 1 addition & 1 deletion cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cmake/gtest.cmake

find_package(GTest CONFIG QUIET)
if (NOT gtest_FOUND)
if (NOT GTest_FOUND)
set(GTEST_GIT_REPO https://github.com/google/googletest.git)
set(GTEST_VERSION release-1.11.0)
message(STATUS "Fetching gtest@${GTEST_VERSION} from repository ${GTEST_GIT_REPO}")
Expand Down
14 changes: 14 additions & 0 deletions cmake/opentelemetry-cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

# cmake/opentelemetry-cpp.cmake

find_package(opentelemetry-cpp QUIET)
Expand Down
14 changes: 14 additions & 0 deletions cmake/spdlog.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

# cmake/spdlog.cmake

find_package(spdlog QUIET)
Expand Down
14 changes: 14 additions & 0 deletions cmake/yaml-cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

# cmake/yaml-cpp.cmake

find_package(yaml-cpp QUIET)
Expand Down
14 changes: 14 additions & 0 deletions emu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

# set target name
set(EMULATOR_LIB_TARGET_NAME hsm-emu)
set(EMULATOR_TOOL_TARGET_NAME hsm-emu-tool)
Expand Down
14 changes: 14 additions & 0 deletions emu/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2021 Institute of Data Security, HIT
#
# 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.

find_package(Threads REQUIRED)
include(gtest)

Expand Down
14 changes: 14 additions & 0 deletions emu/test/emu_test.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright (C) 2021 Institute of Data Security, HIT
//
// 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.

#include "gtest/gtest.h"
#include "sdf.h"
#include "absl/memory/memory.h"
Expand Down
14 changes: 14 additions & 0 deletions emu/test/main.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright (C) 2021 Institute of Data Security, HIT
//
// 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.

#include "gtest/gtest.h"

int main(int argc, char **argv) {
Expand Down
30 changes: 24 additions & 6 deletions include/hsmc/connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include <stdexcept>
#include <string>

#include "exception.h"
#include "sdf_funcs.h"
#include "stf_funcs.h"
#include <hsmc/exception.h>
#include <hsmc/sdf.h>
#include <hsmc/stf.h>
#include <hsmc/instrument.h>

#ifdef ENABLE_OPENTELEMETRY_API
#include <opentelemetry/metrics/provider.h>
Expand Down Expand Up @@ -58,6 +59,9 @@ class HSMC_API Connector : public std::enable_shared_from_this<Connector>, publi
/// Connector的智能指针类型定义
using Ptr = std::shared_ptr<Connector>;

/// 设备导出的函数接口上下文
using FuncContext = std::shared_ptr<void>;

/// Connector的构造函数,需要传入密码设备的动态库路径
/// \param nativeLibPath 访问密码设备的客户端动态库路径
explicit Connector(const std::string &nativeLibPath);
Expand Down Expand Up @@ -1019,7 +1023,21 @@ class HSMC_API Connector : public std::enable_shared_from_this<Connector>, publi
return func;
}

private:
/// 设置SDF函数上下文
/// \param p SDF函数对象
void setSDFContext(const std::shared_ptr<void>& p);

/// 设置STF函数上下文
/// \param p STF函数对象
void setSTFContext(const std::shared_ptr<void>& p);

template<typename T>
auto getSDFContext() const;

template<typename T>
auto getSTFContext() const;

private:
/// HSM设备连接器动态链接库路径
std::string nativeLibPath_;

Expand Down Expand Up @@ -1048,10 +1066,10 @@ class HSMC_API Connector : public std::enable_shared_from_this<Connector>, publi
ConnectorType connType_;

/// SDF的函数集合对象
SDFFuncs sdf_;
FuncContext sdf_;

/// STF的函数结合对象
STFFuncs stf_;
FuncContext stf_;

#ifdef ENABLE_OPENTELEMETRY_API
opentelemetry::nostd::unique_ptr<opentelemetry::metrics::Counter<uint64_t>> counter;
Expand Down
6 changes: 3 additions & 3 deletions include/hsmc/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ inline const char *Exception::name() const noexcept {
return "Exception";
}

#define HSMC_DECLARE_EXCEPTION_CODE(API, CLS, BASE, CODE) \
#define HSMC_DECLARE_EXCEPTION_CODE(API, CLS, BASE, CODE) \
class API CLS: public BASE \
{ \
public: \
explicit CLS(const std::string& msg, int code = CODE); \
const char* name() const noexcept override; \
};

#define HSMC_DECLARE_EXCEPTION(API, CLS, BASE) \
#define HSMC_DECLARE_EXCEPTION(API, CLS, BASE) \
HSMC_DECLARE_EXCEPTION_CODE(API, CLS, BASE, 0)

#define HSMC_IMPLEMENT_EXCEPTION(CLS, BASE, NAME) \
#define HSMC_IMPLEMENT_EXCEPTION(CLS, BASE, NAME) \
CLS::CLS(const std::string& msg, int code) noexcept(noexcept(std::runtime_error(msg))) \
: BASE(msg, code) \
{ \
Expand Down
23 changes: 21 additions & 2 deletions include/hsmc/svs/infosec/session.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
// Copyright (C) 2021 Institute of Data Security, HIT
//
// 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.

#pragma once

#include "hsmc/session.h"
#include "hsmc/svs/infosec/session_impl.h"

namespace hsmc {
namespace svs {
namespace infosec {

/// 信安世纪签名验签服务器扩展接口定义
class HSMC_API Session : public hsmc::Session {
public:
/// 构造函数
/// \param baseSession 父会话对象
explicit Session(const hsmc::Session &baseSession);
/// Session destructor
~Session() override;

/// 扩展函数:生成随机数
/// \param randomData 接收随机数的内存地址
/// \param length 长度
/// \return 成功返回0,失败则返回错误码
int INS_GenRandom(uint8_t *randomData, int length) const;
};

Expand Down
21 changes: 20 additions & 1 deletion include/hsmc/svs/ndsec/session.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
// Copyright (C) 2021 Institute of Data Security, HIT
//
// 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.

#pragma once

#include "hsmc/session.h"
#include "hsmc/svs/ndsec/session_impl.h"

namespace hsmc {
namespace svs {
namespace ndsec {

/// 九维数安签名验签服务器扩展接口定义
class HSMC_API Session : public hsmc::Session {
public:
/// 构造函数
/// \param baseSession 父会话对象
explicit Session(const ::hsmc::Session &baseSession);
~Session() override;

/// 扩展函数:生成随机数
/// \param length 长度
/// \param randomData 接收随机数的内存地址
/// \return 成功返回0,失败则返回错误码
int SVS_GenerateRandom(int length, uint8_t *randomData) const;
};

Expand Down
Loading

0 comments on commit cc2142b

Please sign in to comment.