Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Jan 10, 2024
1 parent b4b5bdd commit 1b4e2c1
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ build/*
tests/bin
tests/.crates.toml
tests/.crates2.json

.vscode

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ ALL_C_SOURCE := c/always_success.c \
c/auth_libecc.c \
c/ckb_hex.h \
c/ripple.h \
c/elf_setup.h
c/elf_setup.h \
tests/auth-c-lock/auth_c_lock.c

fmt:
clang-format -i $(ALL_C_SOURCE)
Expand Down
8 changes: 0 additions & 8 deletions c/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@
#define __builtin_ctzl secp256k1_ctz64_var_debruijn

#include "ckb_consts.h"
#if defined(CKB_USE_SIM)
// exclude ckb_dlfcn.h
#define CKB_C_STDLIB_CKB_DLFCN_H_
#include "ckb_syscall_auth_sim.h"
#else
#include "ckb_syscalls.h"
#endif

#include "ckb_keccak256.h"
#include "secp256k1_helper_20210801.h"
#include "include/secp256k1_schnorrsig.h"
// Must be the last to include, as secp256k1 and this header file both define
// the macros CHECK and CHECK2.

#include "ckb_auth.h"
#undef CKB_SUCCESS
#include "ckb_hex.h"
#include "blake2b.h"
#include "elf_setup.h"
Expand Down
12 changes: 1 addition & 11 deletions c/auth_libecc.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
#include "ckb_auth.h"

// clang-format off
#include "ckb_auth.h"
#include "secp256r1.h"

#include "ckb_consts.h"
#if defined(CKB_USE_SIM)
// exclude ckb_dlfcn.h
#define CKB_C_STDLIB_CKB_DLFCN_H_
#include "ckb_syscall_auth_sim.h"
#else
#include "ckb_syscalls.h"
#endif

#include "blake2b.h"
#undef CKB_SUCCESS
#include "elf_setup.h"
// clang-format on

Expand Down
9 changes: 0 additions & 9 deletions c/cardano/cardano_lock_inc.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#include "ckb_consts.h"
#if defined(CKB_USE_SIM)
// exclude ckb_dlfcn.h
#define CKB_C_STDLIB_CKB_DLFCN_H_
#include "ckb_syscall_auth_sim.h"
#else

#include "ckb_syscalls.h"
#endif

//
#include "blake2b.h"
#include "nanocbor.h"

Expand Down
26 changes: 14 additions & 12 deletions c/ckb_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
// secp256k1 also defines this macros
#undef CHECK2
#undef CHECK
#define CHECK2(cond, code) \
do { \
if (!(cond)) { \
err = code; \
goto exit; \
} \
#define CHECK2(cond, code) \
do { \
if (!(cond)) { \
printf("%s:%d, error code = %d", __FILE__, __LINE__, code); \
err = code; \
goto exit; \
} \
} while (0)

#define CHECK(code) \
do { \
if (code != 0) { \
err = code; \
goto exit; \
} \
#define CHECK(code) \
do { \
if (code != 0) { \
printf("%s:%d, error code = %d", __FILE__, __LINE__, code); \
err = code; \
goto exit; \
} \
} while (0)

#define CKB_AUTH_LEN 21
Expand Down
14 changes: 7 additions & 7 deletions ckb-auth-rs/src/ckb_auth_dl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type CkbAuthValidate = unsafe extern "C" fn(
prefilled_data: *const u8,
auth_algorithm_id: u8,
signature: *const u8,
signature_size: u32,
signature_size: usize,
message: *const u8,
message_size: u32,
message_size: usize,
pubkey_hash: *mut u8,
pubkey_hash_size: u32,
pubkey_hash_size: usize,
) -> i32;

const EXPORTED_FUNC_NAME: &str = "ckb_auth_validate";
Expand Down Expand Up @@ -130,14 +130,14 @@ pub fn ckb_auth_dl(
// TODO:
let rc_code = unsafe {
func(
signature.as_ptr(),
0 as *const u8,
id.algorithm_id.clone().into(),
signature.as_ptr(),
signature.len() as u32,
signature.len() as usize,
message.as_ptr(),
message.len() as u32,
message.len() as usize,
pub_key.as_mut_ptr(),
pub_key.len() as u32,
pub_key.len() as usize,
)
};

Expand Down
Loading

0 comments on commit 1b4e2c1

Please sign in to comment.