Skip to content

Commit

Permalink
chore: setup project
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Chan committed Jan 17, 2024
1 parent e0c464e commit a47c01e
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
78 changes: 78 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CI

on:
push:
branches: [main,dev]
pull_request:
branches: [main,dev]

env:
CARGO_TERM_COLOR: always
CACHE_PATHS: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
jobs:
validity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ${{ env.CACHE_PATHS }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Check source is valid
run: cargo check --workspace

formating:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check Rust formatting with rustfmt
run: cargo fmt --all --check
- uses: brndnmtthws/rust-action-cargo-binstall@v1
with:
packages: taplo-cli
- name: Check TOML formatting with taplo
run: |
taplo fmt --check **/*/Cargo.toml
tests:
needs: validity
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ${{ env.CACHE_PATHS }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run all tests
run: cargo test --workspace --verbose --all-features

clippy:
needs: validity
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ${{ env.CACHE_PATHS }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Lint code with clippy
run: cargo clippy

publish-ability:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check that it will publish to crates
run: |
cargo metadata --offline --format-version 1 --no-deps | jq -r ".workspace_members[]" | while read -r _n _v pathInfo ; do
cd ${pathInfo:13:-1}
cargo publish --no-verify --dry-run
done
shell: bash
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish crates on crates.io

on:
workflow_dispatch:
inputs:
skf-api-version:
description: "major/minor/patch or semver or none if not updating derive crate"
required: false
default: "none"
skf-sys-version:
description: "major/minor/patch or semver or none if not updating derive crate"
required: false
default: "none"

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set git credentials
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Publish crates
uses: kaleidawave/crates-release-gh-action@main
id: release
with:
version: |
{
"skf-api": "${{ github.event.inputs.skf-api-version }}",
"skf-sys": "${{ github.event.inputs.skf-sys-version }}"
}
crates-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Push updated Cargo.toml
run: |
echo '${{ steps.release.outputs.new-versions }}' | jq -r '.[]' | while read -r update; do
git tag "release/$update"
done
git add .
git commit -m "Release: ${{ steps.release.outputs.new-versions-description }}"
git push --tags origin main
58 changes: 58 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Rust ###
# Generated by Cargo
# will have compiled files and executables
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json


### IDEA ###
.idea

# ci dist
/dist

### others ###
/logs
*.log
*.log.*
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
resolver = "2"
members = [
"skf-api",
"skf-sys"
]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rust bindings for GM/T 0016-2012

TDB
19 changes: 19 additions & 0 deletions skf-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "skf-api"
version = "0.1.0"
edition = "2021"
authors = [
"CJ <power4j@outlook.com>",
]
description = """
Rust bindings for GM/T 0016-2012(Smart token cryptography application interface specification).
"""
readme = "README.md"
documentation = "https://docs.rs/skf-api"
repository = "https://github.com/power4j/skf-rs"
license = "MIT"
keywords = ["GM", "cryptography", "PKI"]
categories = ["hardware-support"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions skf-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions skf-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// FIXME: fix this in the future
#[allow(dead_code)]
pub mod skf;
2 changes: 2 additions & 0 deletions skf-api/src/skf/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod skf_ffi;
pub mod types;
Empty file added skf-api/src/skf/skf_ffi.rs
Empty file.
38 changes: 38 additions & 0 deletions skf-api/src/skf/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! GM/T 0016-2012 types
use std::ffi;

type INT8 = i8;
type INT16 = i16;
type INT32 = i32;
type SHORT = INT16;
type LONG = INT32;
type UINT8 = u8;
type UINT16 = u16;
type UINT32 = u32;
type UINT = INT32;
type USHORT = UINT16;
type ULONG = UINT32;

type BOOL = bool;
type BYTE = UINT8;
type CHAR = UINT8;

type WORD = UINT16;

type DWORD = UINT32;
type FLAGS = UINT32;

type LPSTR = *const CHAR;
type HANDLE = ffi::c_void;
type HAPPLICATION = HANDLE;
type HCONTAINER = HANDLE;

/// Version
#[derive(Debug, Copy, Clone)]
#[repr(C)]
#[repr(align(1))]
pub struct Version {
pub major: BYTE,
pub minor: BYTE,
}
21 changes: 21 additions & 0 deletions skf-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "skf-sys"
version = "0.1.0"
edition = "2021"
authors = [
"CJ <power4j@outlook.com>",
]
description = """
Rust bindings for GM/T 0016-2012(Smart token cryptography application interface specification).
"""
readme = "README.md"
documentation = "https://docs.rs/skf-sys"
repository = "https://github.com/power4j/skf-rs"
license = "MIT"
keywords = ["GM", "cryptography", "PKI"]
categories = ["hardware-support"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
skf-api= { path = "../skf-api", version = "0.1.0" }
libloading = "0.8.1"
1 change: 1 addition & 0 deletions skf-sys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions skf-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use skf_api;

pub fn version() -> String {
let version = skf_api::skf::types::Version { major: 0, minor: 1 };
format!("{}.{}", version.major, version.minor)
}

0 comments on commit a47c01e

Please sign in to comment.