Merge branch 'beta' into mergemaster
# Conflicts: # src/main.cpp
This commit is contained in:
151
src/Makefile.am
151
src/Makefile.am
@@ -1,6 +1,8 @@
|
||||
DIST_SUBDIRS = secp256k1 univalue
|
||||
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS)
|
||||
DIST_SUBDIRS = secp256k1 univalue cryptoconditions
|
||||
|
||||
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(SAN_LDFLAGS) $(HARDENED_LDFLAGS)
|
||||
AM_CXXFLAGS = $(SAN_CXXFLAGS) $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS)
|
||||
AM_CPPFLAGS = $(HARDENED_CPPFLAGS)
|
||||
|
||||
if EMBEDDED_LEVELDB
|
||||
LEVELDB_CPPFLAGS += -I$(srcdir)/leveldb/include
|
||||
@@ -14,13 +16,16 @@ $(LIBLEVELDB): $(LIBMEMENV)
|
||||
$(LIBLEVELDB) $(LIBMEMENV):
|
||||
@echo "Building LevelDB ..." && $(MAKE) -C $(@D) $(@F) CXX="$(CXX)" \
|
||||
CC="$(CC)" PLATFORM=$(TARGET_OS) AR="$(AR)" $(LEVELDB_TARGET_FLAGS) \
|
||||
OPT="$(CXXFLAGS) $(CPPFLAGS) -D__STDC_LIMIT_MACROS"
|
||||
OPT="$(AM_CXXFLAGS) $(PIE_FLAGS) $(CXXFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) -D__STDC_LIMIT_MACROS"
|
||||
endif
|
||||
|
||||
BITCOIN_CONFIG_INCLUDES=-I$(builddir)/config
|
||||
BITCOIN_INCLUDES=-I$(builddir) -I$(builddir)/obj $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) $(CRYPTO_CFLAGS) $(SSL_CFLAGS)
|
||||
|
||||
BITCOIN_INCLUDES += -I$(srcdir)/secp256k1/include
|
||||
BITCOIN_INCLUDES += -I$(srcdir)/cryptoconditions/include
|
||||
BITCOIN_INCLUDES += -I$(srcdir)/snark
|
||||
BITCOIN_INCLUDES += -I$(srcdir)/snark/libsnark
|
||||
BITCOIN_INCLUDES += -I$(srcdir)/univalue/include
|
||||
|
||||
if TARGET_WINDOWS
|
||||
@@ -38,15 +43,32 @@ LIBBITCOIN_CLI=libbitcoin_cli.a
|
||||
LIBBITCOIN_UTIL=libbitcoin_util.a
|
||||
LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
|
||||
LIBSECP256K1=secp256k1/libsecp256k1.la
|
||||
LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la
|
||||
LIBSNARK=snark/libsnark.a
|
||||
LIBUNIVALUE=univalue/libunivalue.la
|
||||
LIBZCASH=libzcash.a -lcurl
|
||||
|
||||
$(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*)
|
||||
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
|
||||
|
||||
LIBSNARK_CXXFLAGS = -fPIC -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1 -fstack-protector-all
|
||||
LIBSNARK_CONFIG_FLAGS = CURVE=ALT_BN128 NO_PROCPS=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT NO_COPY_DEPINST=1 NO_COMPILE_LIBGTEST=1
|
||||
if HAVE_OPENMP
|
||||
LIBSNARK_CONFIG_FLAGS += MULTICORE=1
|
||||
endif
|
||||
|
||||
$(LIBSNARK): $(wildcard snark/src/*)
|
||||
$(AM_V_at) CXXFLAGS="$(LIBSNARK_CXXFLAGS)" $(MAKE) $(AM_MAKEFLAGS) -C snark/ DEPINST="$(LIBSNARK_DEPINST)" $(LIBSNARK_CONFIG_FLAGS) OPTFLAGS="-O2 -march=x86-64"
|
||||
|
||||
libsnark-tests: $(wildcard snark/src/*)
|
||||
$(AM_V_at) CXXFLAGS="$(LIBSNARK_CXXFLAGS)" $(MAKE) $(AM_MAKEFLAGS) -C snark/ check DEPINST="$(LIBSNARK_DEPINST)" $(LIBSNARK_CONFIG_FLAGS) OPTFLAGS="-O2 -march=x86-64"
|
||||
|
||||
$(LIBUNIVALUE): $(wildcard univalue/lib/*)
|
||||
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue/
|
||||
|
||||
$(LIBCRYPTOCONDITIONS): $(wildcard cryptoconditions/src/*) $(wildcard cryptoconditions/include/*)
|
||||
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
|
||||
|
||||
# Make is not made aware of per-object dependencies to avoid limiting building parallelization
|
||||
# But to build the less dependent modules first, we manually select their order here:
|
||||
EXTRA_LIBRARIES = \
|
||||
@@ -63,6 +85,9 @@ endif
|
||||
if ENABLE_ZMQ
|
||||
EXTRA_LIBRARIES += libbitcoin_zmq.a
|
||||
endif
|
||||
if ENABLE_PROTON
|
||||
EXTRA_LIBRARIES += libbitcoin_proton.a
|
||||
endif
|
||||
|
||||
if BUILD_BITCOIN_LIBS
|
||||
lib_LTLIBRARIES = libzcashconsensus.la
|
||||
@@ -94,17 +119,23 @@ LIBZCASH_H = \
|
||||
zcash/util.h \
|
||||
zcash/Zcash.h
|
||||
|
||||
.PHONY: FORCE check-symbols check-security
|
||||
.PHONY: FORCE collate-libsnark check-symbols check-security
|
||||
# bitcoin core #
|
||||
BITCOIN_CORE_H = \
|
||||
addrman.h \
|
||||
alert.h \
|
||||
amount.h \
|
||||
amqp/amqpabstractnotifier.h \
|
||||
amqp/amqpconfig.h \
|
||||
amqp/amqpnotificationinterface.h \
|
||||
amqp/amqppublishnotifier.h \
|
||||
amqp/amqpsender.h \
|
||||
arith_uint256.h \
|
||||
asyncrpcoperation.h \
|
||||
asyncrpcqueue.h \
|
||||
base58.h \
|
||||
bloom.h \
|
||||
cc/eval.h \
|
||||
chain.h \
|
||||
chainparams.h \
|
||||
chainparamsbase.h \
|
||||
@@ -121,11 +152,11 @@ BITCOIN_CORE_H = \
|
||||
compressor.h \
|
||||
consensus/consensus.h \
|
||||
consensus/params.h \
|
||||
consensus/upgrades.h \
|
||||
consensus/validation.h \
|
||||
core_io.h \
|
||||
core_memusage.h \
|
||||
eccryptoverify.h \
|
||||
ecwrapper.h \
|
||||
deprecation.h \
|
||||
hash.h \
|
||||
httprpc.h \
|
||||
httpserver.h \
|
||||
@@ -143,6 +174,8 @@ BITCOIN_CORE_H = \
|
||||
net.h \
|
||||
netbase.h \
|
||||
noui.h \
|
||||
paymentdisclosure.h \
|
||||
paymentdisclosuredb.h \
|
||||
policy/fees.h \
|
||||
pow.h \
|
||||
primitives/block.h \
|
||||
@@ -158,7 +191,7 @@ BITCOIN_CORE_H = \
|
||||
script/interpreter.h \
|
||||
script/script.h \
|
||||
script/script_error.h \
|
||||
script/sigcache.h \
|
||||
script/serverchecker.h \
|
||||
script/sign.h \
|
||||
script/standard.h \
|
||||
serialize.h \
|
||||
@@ -185,7 +218,9 @@ BITCOIN_CORE_H = \
|
||||
utiltime.h \
|
||||
validationinterface.h \
|
||||
version.h \
|
||||
wallet/asyncrpcoperation_mergetoaddress.h \
|
||||
wallet/asyncrpcoperation_sendmany.h \
|
||||
wallet/asyncrpcoperation_shieldcoinbase.h \
|
||||
wallet/crypter.h \
|
||||
wallet/db.h \
|
||||
wallet/wallet.h \
|
||||
@@ -204,7 +239,8 @@ obj/build.h: FORCE
|
||||
libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h
|
||||
|
||||
# server: zcashd
|
||||
libbitcoin_server_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
|
||||
libbitcoin_server_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
|
||||
libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_server_a_SOURCES = \
|
||||
sendalert.cpp \
|
||||
addrman.cpp \
|
||||
@@ -213,8 +249,13 @@ libbitcoin_server_a_SOURCES = \
|
||||
asyncrpcoperation.cpp \
|
||||
asyncrpcqueue.cpp \
|
||||
bloom.cpp \
|
||||
cc/eval.cpp \
|
||||
cc/importpayout.cpp \
|
||||
cc/disputepayout.cpp \
|
||||
cc/betprotocol.cpp \
|
||||
chain.cpp \
|
||||
checkpoints.cpp \
|
||||
deprecation.cpp \
|
||||
httprpc.cpp \
|
||||
httpserver.cpp \
|
||||
init.cpp \
|
||||
@@ -225,6 +266,8 @@ libbitcoin_server_a_SOURCES = \
|
||||
miner.cpp \
|
||||
net.cpp \
|
||||
noui.cpp \
|
||||
paymentdisclosure.cpp \
|
||||
paymentdisclosuredb.cpp \
|
||||
policy/fees.cpp \
|
||||
pow.cpp \
|
||||
rest.cpp \
|
||||
@@ -234,7 +277,7 @@ libbitcoin_server_a_SOURCES = \
|
||||
rpcnet.cpp \
|
||||
rpcrawtransaction.cpp \
|
||||
rpcserver.cpp \
|
||||
script/sigcache.cpp \
|
||||
script/serverchecker.cpp \
|
||||
timedata.cpp \
|
||||
torcontrol.cpp \
|
||||
txdb.cpp \
|
||||
@@ -247,23 +290,40 @@ if ENABLE_ZMQ
|
||||
LIBBITCOIN_ZMQ=libbitcoin_zmq.a
|
||||
|
||||
libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS)
|
||||
libbitcoin_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_zmq_a_SOURCES = \
|
||||
zmq/zmqabstractnotifier.cpp \
|
||||
zmq/zmqnotificationinterface.cpp \
|
||||
zmq/zmqpublishnotifier.cpp
|
||||
endif
|
||||
|
||||
if ENABLE_PROTON
|
||||
LIBBITCOIN_PROTON=libbitcoin_proton.a
|
||||
|
||||
libbitcoin_proton_a_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
libbitcoin_proton_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_proton_a_SOURCES = \
|
||||
amqp/amqpabstractnotifier.cpp \
|
||||
amqp/amqpnotificationinterface.cpp \
|
||||
amqp/amqppublishnotifier.cpp
|
||||
endif
|
||||
|
||||
# wallet: zcashd, but only linked when wallet enabled
|
||||
libbitcoin_wallet_a_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_wallet_a_SOURCES = \
|
||||
utiltest.cpp \
|
||||
utiltest.h \
|
||||
zcbenchmarks.cpp \
|
||||
zcbenchmarks.h \
|
||||
wallet/asyncrpcoperation_mergetoaddress.cpp \
|
||||
wallet/asyncrpcoperation_sendmany.cpp \
|
||||
wallet/asyncrpcoperation_shieldcoinbase.cpp \
|
||||
wallet/crypter.cpp \
|
||||
wallet/db.cpp \
|
||||
paymentdisclosure.cpp \
|
||||
paymentdisclosuredb.cpp \
|
||||
wallet/rpcdisclosure.cpp \
|
||||
wallet/rpcdump.cpp \
|
||||
wallet/rpcwallet.cpp \
|
||||
wallet/wallet.cpp \
|
||||
@@ -273,7 +333,8 @@ libbitcoin_wallet_a_SOURCES = \
|
||||
$(LIBZCASH_H)
|
||||
|
||||
# crypto primitives library
|
||||
crypto_libbitcoin_crypto_a_CPPFLAGS = $(BITCOIN_CONFIG_INCLUDES)
|
||||
crypto_libbitcoin_crypto_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_CONFIG_INCLUDES)
|
||||
crypto_libbitcoin_crypto_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
crypto_libbitcoin_crypto_a_SOURCES = \
|
||||
crypto/common.h \
|
||||
crypto/equihash.cpp \
|
||||
@@ -305,7 +366,8 @@ crypto_libbitcoin_crypto_a_SOURCES += \
|
||||
endif
|
||||
|
||||
# common: shared between zcashd and non-server tools
|
||||
libbitcoin_common_a_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
libbitcoin_common_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_common_a_SOURCES = \
|
||||
amount.cpp \
|
||||
arith_uint256.cpp \
|
||||
@@ -313,10 +375,9 @@ libbitcoin_common_a_SOURCES = \
|
||||
chainparams.cpp \
|
||||
coins.cpp \
|
||||
compressor.cpp \
|
||||
consensus/upgrades.cpp \
|
||||
core_read.cpp \
|
||||
core_write.cpp \
|
||||
eccryptoverify.cpp \
|
||||
ecwrapper.cpp \
|
||||
hash.cpp \
|
||||
key.cpp \
|
||||
keystore.cpp \
|
||||
@@ -326,6 +387,7 @@ libbitcoin_common_a_SOURCES = \
|
||||
protocol.cpp \
|
||||
pubkey.cpp \
|
||||
scheduler.cpp \
|
||||
script/cc.cpp \
|
||||
script/interpreter.cpp \
|
||||
script/script.cpp \
|
||||
script/script_error.cpp \
|
||||
@@ -337,7 +399,8 @@ libbitcoin_common_a_SOURCES = \
|
||||
# util: shared between all executables.
|
||||
# This library *must* be included to make sure that the glibc
|
||||
# backward-compatibility objects and their sanity checks are linked.
|
||||
libbitcoin_util_a_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
libbitcoin_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_util_a_SOURCES = \
|
||||
support/pagelocker.cpp \
|
||||
chainparamsbase.cpp \
|
||||
@@ -362,7 +425,8 @@ libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp
|
||||
endif
|
||||
|
||||
# cli: zcash-cli
|
||||
libbitcoin_cli_a_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
libbitcoin_cli_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_cli_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_cli_a_SOURCES = \
|
||||
rpcclient.cpp \
|
||||
$(BITCOIN_CORE_H) \
|
||||
@@ -373,7 +437,8 @@ nodist_libbitcoin_util_a_SOURCES = $(srcdir)/obj/build.h
|
||||
|
||||
# bitcoind binary #
|
||||
komodod_SOURCES = bitcoind.cpp
|
||||
komodod_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
komodod_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
komodod_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
komodod_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
@@ -387,9 +452,11 @@ komodod_LDADD = \
|
||||
$(LIBBITCOIN_UTIL) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBSNARK) \
|
||||
$(LIBLEVELDB) \
|
||||
$(LIBMEMENV) \
|
||||
$(LIBSECP256K1)
|
||||
$(LIBSECP256K1) \
|
||||
$(LIBCRYPTOCONDITIONS)
|
||||
|
||||
if ENABLE_ZMQ
|
||||
komodod_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
|
||||
@@ -404,16 +471,19 @@ komodod_LDADD += \
|
||||
$(BDB_LIBS) \
|
||||
$(SSL_LIBS) \
|
||||
$(CRYPTO_LIBS) \
|
||||
$(MINIUPNPC_LIBS) \
|
||||
$(EVENT_PTHREADS_LIBS) \
|
||||
$(EVENT_LIBS) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH_LIBS)
|
||||
|
||||
if ENABLE_PROTON
|
||||
komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS)
|
||||
endif
|
||||
|
||||
# bitcoin-cli binary #
|
||||
komodo_cli_SOURCES = bitcoin-cli.cpp
|
||||
komodo_cli_CPPFLAGS = $(BITCOIN_INCLUDES) $(EVENT_CFLAGS)
|
||||
komodo_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS)
|
||||
komodo_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
komodo_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
@@ -429,13 +499,15 @@ komodo_cli_LDADD = \
|
||||
$(CRYPTO_LIBS) \
|
||||
$(EVENT_LIBS) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBSNARK) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH_LIBS)
|
||||
#
|
||||
|
||||
# zcash-tx binary #
|
||||
komodo_tx_SOURCES = komodo-tx.cpp
|
||||
komodo_tx_CPPFLAGS = $(BITCOIN_INCLUDES)
|
||||
komodo_tx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
komodo_tx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
komodo_tx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
|
||||
if TARGET_WINDOWS
|
||||
@@ -449,8 +521,10 @@ komodo_tx_LDADD = \
|
||||
$(LIBBITCOIN_UTIL) \
|
||||
$(LIBSECP256K1) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBSNARK) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH_LIBS)
|
||||
$(LIBZCASH_LIBS) \
|
||||
$(LIBCRYPTOCONDITIONS)
|
||||
|
||||
komodo_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
|
||||
#
|
||||
@@ -472,12 +546,10 @@ libzcash_a_SOURCES = \
|
||||
zcash/circuit/prfs.tcc \
|
||||
zcash/circuit/utils.tcc
|
||||
|
||||
libzcash_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) -pipe -O1 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES)
|
||||
|
||||
libzcash_a_CXXFLAGS = $(HARDENED_CXXFLAGS) -fwrapv -fno-strict-aliasing
|
||||
|
||||
#libzcash_a_LDFLAGS = $(HARDENED_LDFLAGS)
|
||||
libzcash_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) $(HARDENED_CXXFLAGS) $(HARDENED_LDFLAGS) -pipe $(SAN_LDFLAGS) -O1 -g -Wstack-protector $(SAN_CXXFLAGS) -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES)
|
||||
|
||||
libzcash_a_CXXFLAGS = $(SAN_CXXFLAGS) $(HARDENED_CXXFLAGS) -fwrapv -fno-strict-aliasing
|
||||
libzcash_a_LDFLAGS = $(SAN_LDFLAGS) $(HARDENED_LDFLAGS)
|
||||
libzcash_a_CPPFLAGS += -DMONTGOMERY_OUTPUT
|
||||
|
||||
# zcashconsensus library #
|
||||
@@ -490,8 +562,6 @@ libzcashconsensus_la_SOURCES = \
|
||||
crypto/sha1.cpp \
|
||||
crypto/sha256.cpp \
|
||||
crypto/sha512.cpp \
|
||||
eccryptoverify.cpp \
|
||||
ecwrapper.cpp \
|
||||
hash.cpp \
|
||||
primitives/transaction.cpp \
|
||||
pubkey.cpp \
|
||||
@@ -505,9 +575,10 @@ if GLIBC_BACK_COMPAT
|
||||
libzcashconsensus_la_SOURCES += compat/glibc_compat.cpp
|
||||
endif
|
||||
|
||||
libzcashconsensus_la_LDFLAGS = -no-undefined $(RELDFLAGS)
|
||||
libzcashconsensus_la_LIBADD = $(CRYPTO_LIBS)
|
||||
libzcashconsensus_la_CPPFLAGS = $(CRYPTO_CFLAGS) -I$(builddir)/obj -DBUILD_BITCOIN_INTERNAL
|
||||
libzcashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
|
||||
libzcashconsensus_la_LIBADD = $(LIBSECP256K1)
|
||||
libzcashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
|
||||
libzcashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
|
||||
endif
|
||||
#
|
||||
@@ -516,11 +587,12 @@ CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno */*.gcno wal
|
||||
|
||||
DISTCLEANFILES = obj/build.h
|
||||
|
||||
EXTRA_DIST = leveldb
|
||||
EXTRA_DIST = leveldb snark
|
||||
|
||||
clean-local:
|
||||
-$(MAKE) -C leveldb clean
|
||||
-$(MAKE) -C secp256k1 clean
|
||||
-$(MAKE) -C snark clean
|
||||
rm -f leveldb/*/*.gcno leveldb/helpers/memenv/*.gcno
|
||||
-rm -f config.h
|
||||
|
||||
@@ -530,27 +602,28 @@ clean-local:
|
||||
|
||||
.mm.o:
|
||||
$(AM_V_CXX) $(OBJCXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||
$(CPPFLAGS) $(AM_CXXFLAGS) $(AM_CXXFLAGS) $(PIE_FLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
check-symbols: $(bin_PROGRAMS)
|
||||
if GLIBC_BACK_COMPAT
|
||||
@echo "Checking glibc back compat of [$(bin_PROGRAMS)]..."
|
||||
$(AM_V_at) READELF=$(READELF) CPPFILT=$(CPPFILT) $(top_srcdir)/contrib/devtools/symbol-check.py < $(bin_PROGRAMS)
|
||||
$(AM_V_at) READELF=$(READELF) CPPFILT=$(CPPFILT) $(top_srcdir)/contrib/devtools/symbol-check.py $(bin_PROGRAMS)
|
||||
endif
|
||||
|
||||
check-security: $(bin_PROGRAMS)
|
||||
if HARDEN
|
||||
@echo "Checking binary security of [$(bin_PROGRAMS)]..."
|
||||
$(AM_V_at) READELF=$(READELF) OBJDUMP=$(OBJDUMP) $(top_srcdir)/contrib/devtools/security-check.py < $(bin_PROGRAMS)
|
||||
$(AM_V_at) READELF=$(READELF) OBJDUMP=$(OBJDUMP) $(top_srcdir)/contrib/devtools/security-check.py $(bin_PROGRAMS)
|
||||
endif
|
||||
|
||||
%.pb.cc %.pb.h: %.proto
|
||||
@test -f $(PROTOC)
|
||||
$(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(abspath $(<D) $<)
|
||||
|
||||
#if ENABLE_TESTS
|
||||
if ENABLE_TESTS
|
||||
include Makefile.ktest.include
|
||||
#include Makefile.test.include
|
||||
#include Makefile.gtest.include
|
||||
#endif
|
||||
endif
|
||||
|
||||
include Makefile.zcash.include
|
||||
|
||||
@@ -19,7 +19,9 @@ zcash_gtest_SOURCES += \
|
||||
endif
|
||||
zcash_gtest_SOURCES += \
|
||||
gtest/test_tautology.cpp \
|
||||
gtest/test_deprecation.cpp \
|
||||
gtest/test_equihash.cpp \
|
||||
gtest/test_httprpc.cpp \
|
||||
gtest/test_joinsplit.cpp \
|
||||
gtest/test_keystore.cpp \
|
||||
gtest/test_noteencryption.cpp \
|
||||
@@ -31,17 +33,21 @@ zcash_gtest_SOURCES += \
|
||||
gtest/test_random.cpp \
|
||||
gtest/test_rpc.cpp \
|
||||
gtest/test_transaction.cpp \
|
||||
gtest/test_upgrades.cpp \
|
||||
gtest/test_validation.cpp \
|
||||
gtest/test_circuit.cpp \
|
||||
gtest/test_txid.cpp \
|
||||
gtest/test_libzcash_utils.cpp \
|
||||
gtest/test_proofs.cpp \
|
||||
gtest/test_paymentdisclosure.cpp \
|
||||
gtest/test_checkblock.cpp
|
||||
if ENABLE_WALLET
|
||||
zcash_gtest_SOURCES += \
|
||||
wallet/gtest/test_wallet.cpp
|
||||
endif
|
||||
|
||||
komodo_gtest_CPPFLAGS = -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC
|
||||
komodo_gtest_CPPFLAGS = $(AM_CPPFLAGS) -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC $(BITCOIN_INCLUDES)
|
||||
komodo_gtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
|
||||
komodo_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
|
||||
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1)
|
||||
@@ -52,7 +58,14 @@ if ENABLE_WALLET
|
||||
komodo_gtest_LDADD += $(LIBBITCOIN_WALLET)
|
||||
endif
|
||||
|
||||
komodo_gtest_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS)
|
||||
komodo_gtest_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(LIBZCASH) $(LIBSNARK) $(LIBZCASH_LIBS)
|
||||
|
||||
if ENABLE_PROTON
|
||||
komodo_gtest_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS)
|
||||
endif
|
||||
|
||||
|
||||
komodo_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
|
||||
|
||||
komodo_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
|
||||
|
||||
|
||||
16
src/Makefile.ktest.include
Normal file
16
src/Makefile.ktest.include
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
TESTS += komodo-test
|
||||
bin_PROGRAMS += komodo-test
|
||||
|
||||
# tool for generating our public parameters
|
||||
komodo_test_SOURCES = \
|
||||
test-komodo/main.cpp \
|
||||
test-komodo/test_cryptoconditions.cpp \
|
||||
test-komodo/test_eval_bet.cpp \
|
||||
test-komodo/test_eval_notarisation.cpp
|
||||
|
||||
komodo_test_CPPFLAGS = $(komodod_CPPFLAGS)
|
||||
|
||||
komodo_test_LDADD = -lgtest $(komodod_LDADD)
|
||||
|
||||
komodo_test_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
|
||||
@@ -99,20 +99,25 @@ BITCOIN_TESTS += \
|
||||
endif
|
||||
|
||||
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
|
||||
test_test_bitcoin_CPPFLAGS = -fopenmp $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS)
|
||||
test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) -fopenmp $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS)
|
||||
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
|
||||
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
|
||||
test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
if ENABLE_WALLET
|
||||
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
|
||||
endif
|
||||
|
||||
test_test_bitcoin_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS)
|
||||
test_test_bitcoin_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(LIBZCASH) $(LIBSNARK) $(LIBZCASH_LIBS)
|
||||
test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
|
||||
|
||||
if ENABLE_ZMQ
|
||||
test_test_bitcoin_LDADD += $(ZMQ_LIBS)
|
||||
endif
|
||||
|
||||
if ENABLE_PROTON
|
||||
test_test_bitcoin_LDADD += $(PROTON_LIBS)
|
||||
endif
|
||||
|
||||
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
|
||||
|
||||
$(BITCOIN_TESTS): $(GENERATED_TEST_FILES)
|
||||
|
||||
@@ -4,19 +4,28 @@ noinst_PROGRAMS += \
|
||||
|
||||
# tool for generating our public parameters
|
||||
zcash_GenerateParams_SOURCES = zcash/GenerateParams.cpp
|
||||
zcash_GenerateParams_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
zcash_GenerateParams_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
zcash_GenerateParams_LDADD = \
|
||||
$(BOOST_LIBS) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBSNARK) \
|
||||
$(LIBBITCOIN_UTIL) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH_LIBS)
|
||||
|
||||
# tool for profiling the creation of joinsplits
|
||||
zcash_CreateJoinSplit_SOURCES = zcash/CreateJoinSplit.cpp
|
||||
zcash_CreateJoinSplit_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
zcash_CreateJoinSplit_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
zcash_CreateJoinSplit_LDADD = \
|
||||
$(LIBBITCOIN_COMMON) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBSNARK) \
|
||||
$(LIBBITCOIN_UTIL) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(BOOST_LIBS) \
|
||||
$(LIBZCASH_LIBS)
|
||||
$(LIBZCASH_LIBS) \
|
||||
$(LIBCRYPTOCONDITIONS) \
|
||||
$(LIBSECP256K1)
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ protected:
|
||||
//! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
|
||||
CAddrInfo Select_(bool newOnly);
|
||||
|
||||
//! Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic.
|
||||
//! Wraps GetRandInt to allow tests to override RandomInt and make it deterministic.
|
||||
virtual int RandomInt(int nMax);
|
||||
|
||||
#ifdef DEBUG_ADDRMAN
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "tinyformat.h"
|
||||
|
||||
const std::string CURRENCY_UNIT = "ZEC";
|
||||
|
||||
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
|
||||
{
|
||||
if (nSize > 0)
|
||||
@@ -27,5 +29,5 @@ CAmount CFeeRate::GetFee(size_t nSize) const
|
||||
|
||||
std::string CFeeRate::ToString() const
|
||||
{
|
||||
return strprintf("%d.%08d BTC/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN);
|
||||
return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ typedef int64_t CAmount;
|
||||
static const CAmount COIN = 100000000;
|
||||
static const CAmount CENT = 1000000;
|
||||
|
||||
extern const std::string CURRENCY_UNIT;
|
||||
|
||||
/** No amount larger than this (in satoshi) is valid.
|
||||
*
|
||||
* Note that this constant is *not* the total money supply, which in Bitcoin
|
||||
|
||||
21
src/amqp/amqpabstractnotifier.cpp
Normal file
21
src/amqp/amqpabstractnotifier.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "amqpabstractnotifier.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
AMQPAbstractNotifier::~AMQPAbstractNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
bool AMQPAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AMQPAbstractNotifier::NotifyTransaction(const CTransaction &/*transaction*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
43
src/amqp/amqpabstractnotifier.h
Normal file
43
src/amqp/amqpabstractnotifier.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef ZCASH_AMQP_AMQPABSTRACTNOTIFIER_H
|
||||
#define ZCASH_AMQP_AMQPABSTRACTNOTIFIER_H
|
||||
|
||||
#include "amqpconfig.h"
|
||||
|
||||
class CBlockIndex;
|
||||
class AMQPAbstractNotifier;
|
||||
|
||||
typedef AMQPAbstractNotifier* (*AMQPNotifierFactory)();
|
||||
|
||||
class AMQPAbstractNotifier
|
||||
{
|
||||
public:
|
||||
AMQPAbstractNotifier() { }
|
||||
virtual ~AMQPAbstractNotifier();
|
||||
|
||||
template <typename T>
|
||||
static AMQPAbstractNotifier* Create()
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
|
||||
std::string GetType() const { return type; }
|
||||
void SetType(const std::string &t) { type = t; }
|
||||
std::string GetAddress() const { return address; }
|
||||
void SetAddress(const std::string &a) { address = a; }
|
||||
|
||||
virtual bool Initialize() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual bool NotifyBlock(const CBlockIndex *pindex);
|
||||
virtual bool NotifyTransaction(const CTransaction &transaction);
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
std::string address;
|
||||
};
|
||||
|
||||
#endif // ZCASH_AMQP_AMQPABSTRACTNOTIFIER_H
|
||||
33
src/amqp/amqpconfig.h
Normal file
33
src/amqp/amqpconfig.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef ZCASH_AMQP_AMQPCONFIG_H
|
||||
#define ZCASH_AMQP_AMQPCONFIG_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config/bitcoin-config.h"
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#if ENABLE_PROTON
|
||||
#include <proton/connection.hpp>
|
||||
#include <proton/connection_options.hpp>
|
||||
#include <proton/container.hpp>
|
||||
#include <proton/default_container.hpp>
|
||||
#include <proton/message.hpp>
|
||||
#include <proton/message_id.hpp>
|
||||
#include <proton/messaging_handler.hpp>
|
||||
#include <proton/thread_safe.hpp>
|
||||
#include <proton/tracker.hpp>
|
||||
#include <proton/transport.hpp>
|
||||
#include <proton/types.hpp>
|
||||
#include <proton/url.hpp>
|
||||
#endif
|
||||
|
||||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
#endif // ZCASH_AMQP_AMQPCONFIG_H
|
||||
136
src/amqp/amqpnotificationinterface.cpp
Normal file
136
src/amqp/amqpnotificationinterface.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "amqpnotificationinterface.h"
|
||||
#include "amqppublishnotifier.h"
|
||||
|
||||
#include "version.h"
|
||||
#include "main.h"
|
||||
#include "streams.h"
|
||||
#include "util.h"
|
||||
|
||||
// AMQP 1.0 Support
|
||||
//
|
||||
// The boost::signals2 signals and slot system is thread safe, so CValidationInterface listeners
|
||||
// can be invoked from any thread.
|
||||
//
|
||||
// Currently signals are fired from main.cpp so the callbacks should be invoked on the same thread.
|
||||
// It should be safe to share objects responsible for sending, as they should not be run concurrently
|
||||
// across different threads.
|
||||
//
|
||||
// Developers should be mindful of where notifications are fired to avoid potential race conditions.
|
||||
// For example, different signals targeting the same address could be fired from different threads
|
||||
// in different parts of the system around the same time.
|
||||
//
|
||||
// Like the ZMQ notification interface, if a notifier fails to send a message, the notifier is shut down.
|
||||
//
|
||||
|
||||
AMQPNotificationInterface::AMQPNotificationInterface()
|
||||
{
|
||||
}
|
||||
|
||||
AMQPNotificationInterface::~AMQPNotificationInterface()
|
||||
{
|
||||
Shutdown();
|
||||
|
||||
for (std::list<AMQPAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ++i) {
|
||||
delete *i;
|
||||
}
|
||||
}
|
||||
|
||||
AMQPNotificationInterface* AMQPNotificationInterface::CreateWithArguments(const std::map<std::string, std::string> &args)
|
||||
{
|
||||
AMQPNotificationInterface* notificationInterface = nullptr;
|
||||
std::map<std::string, AMQPNotifierFactory> factories;
|
||||
std::list<AMQPAbstractNotifier*> notifiers;
|
||||
|
||||
factories["pubhashblock"] = AMQPAbstractNotifier::Create<AMQPPublishHashBlockNotifier>;
|
||||
factories["pubhashtx"] = AMQPAbstractNotifier::Create<AMQPPublishHashTransactionNotifier>;
|
||||
factories["pubrawblock"] = AMQPAbstractNotifier::Create<AMQPPublishRawBlockNotifier>;
|
||||
factories["pubrawtx"] = AMQPAbstractNotifier::Create<AMQPPublishRawTransactionNotifier>;
|
||||
|
||||
for (std::map<std::string, AMQPNotifierFactory>::const_iterator i=factories.begin(); i!=factories.end(); ++i) {
|
||||
std::map<std::string, std::string>::const_iterator j = args.find("-amqp" + i->first);
|
||||
if (j!=args.end()) {
|
||||
AMQPNotifierFactory factory = i->second;
|
||||
std::string address = j->second;
|
||||
AMQPAbstractNotifier *notifier = factory();
|
||||
notifier->SetType(i->first);
|
||||
notifier->SetAddress(address);
|
||||
notifiers.push_back(notifier);
|
||||
}
|
||||
}
|
||||
|
||||
if (!notifiers.empty()) {
|
||||
notificationInterface = new AMQPNotificationInterface();
|
||||
notificationInterface->notifiers = notifiers;
|
||||
|
||||
if (!notificationInterface->Initialize()) {
|
||||
delete notificationInterface;
|
||||
notificationInterface = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return notificationInterface;
|
||||
}
|
||||
|
||||
// Called at startup to conditionally set up
|
||||
bool AMQPNotificationInterface::Initialize()
|
||||
{
|
||||
LogPrint("amqp", "amqp: Initialize notification interface\n");
|
||||
|
||||
std::list<AMQPAbstractNotifier*>::iterator i = notifiers.begin();
|
||||
for (; i != notifiers.end(); ++i) {
|
||||
AMQPAbstractNotifier *notifier = *i;
|
||||
if (notifier->Initialize()) {
|
||||
LogPrint("amqp", "amqp: Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
|
||||
} else {
|
||||
LogPrint("amqp", "amqp: Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != notifiers.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Called during shutdown sequence
|
||||
void AMQPNotificationInterface::Shutdown()
|
||||
{
|
||||
LogPrint("amqp", "amqp: Shutdown notification interface\n");
|
||||
|
||||
for (std::list<AMQPAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ++i) {
|
||||
AMQPAbstractNotifier *notifier = *i;
|
||||
notifier->Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
void AMQPNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
{
|
||||
for (std::list<AMQPAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ) {
|
||||
AMQPAbstractNotifier *notifier = *i;
|
||||
if (notifier->NotifyBlock(pindex)) {
|
||||
i++;
|
||||
} else {
|
||||
notifier->Shutdown();
|
||||
i = notifiers.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AMQPNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
|
||||
{
|
||||
for (std::list<AMQPAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ) {
|
||||
AMQPAbstractNotifier *notifier = *i;
|
||||
if (notifier->NotifyTransaction(tx)) {
|
||||
i++;
|
||||
} else {
|
||||
notifier->Shutdown();
|
||||
i = notifiers.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/amqp/amqpnotificationinterface.h
Normal file
36
src/amqp/amqpnotificationinterface.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef ZCASH_AMQP_AMQPNOTIFICATIONINTERFACE_H
|
||||
#define ZCASH_AMQP_AMQPNOTIFICATIONINTERFACE_H
|
||||
|
||||
#include "validationinterface.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class CBlockIndex;
|
||||
class AMQPAbstractNotifier;
|
||||
|
||||
class AMQPNotificationInterface : public CValidationInterface
|
||||
{
|
||||
public:
|
||||
virtual ~AMQPNotificationInterface();
|
||||
|
||||
static AMQPNotificationInterface* CreateWithArguments(const std::map<std::string, std::string> &args);
|
||||
|
||||
protected:
|
||||
bool Initialize();
|
||||
void Shutdown();
|
||||
|
||||
// CValidationInterface
|
||||
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
|
||||
void UpdatedBlockTip(const CBlockIndex *pindex);
|
||||
|
||||
private:
|
||||
AMQPNotificationInterface();
|
||||
|
||||
std::list<AMQPAbstractNotifier*> notifiers;
|
||||
};
|
||||
|
||||
#endif // ZCASH_AMQP_AMQPNOTIFICATIONINTERFACE_H
|
||||
177
src/amqp/amqppublishnotifier.cpp
Normal file
177
src/amqp/amqppublishnotifier.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "amqppublishnotifier.h"
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "amqpsender.h"
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
static std::multimap<std::string, AMQPAbstractPublishNotifier*> mapPublishNotifiers;
|
||||
|
||||
static const char *MSG_HASHBLOCK = "hashblock";
|
||||
static const char *MSG_HASHTX = "hashtx";
|
||||
static const char *MSG_RAWBLOCK = "rawblock";
|
||||
static const char *MSG_RAWTX = "rawtx";
|
||||
|
||||
// Invoke this method from a new thread to run the proton container event loop.
|
||||
void AMQPAbstractPublishNotifier::SpawnProtonContainer()
|
||||
{
|
||||
try {
|
||||
proton::default_container(*handler_).run();
|
||||
}
|
||||
catch (const proton::error_condition &e) {
|
||||
LogPrint("amqp", "amqp: container error: %s\n", e.what());
|
||||
}
|
||||
catch (const std::runtime_error &e) {
|
||||
LogPrint("amqp", "amqp: runtime error: %s\n", e.what());
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
LogPrint("amqp", "amqp: exception: %s\n", e.what());
|
||||
}
|
||||
catch (...) {
|
||||
LogPrint("amqp", "amqp: unknown error\n");
|
||||
}
|
||||
handler_->terminate();
|
||||
}
|
||||
|
||||
bool AMQPAbstractPublishNotifier::Initialize()
|
||||
{
|
||||
std::multimap<std::string, AMQPAbstractPublishNotifier*>::iterator i = mapPublishNotifiers.find(address);
|
||||
|
||||
if (i == mapPublishNotifiers.end()) {
|
||||
try {
|
||||
handler_ = std::make_shared<AMQPSender>(address);
|
||||
thread_ = std::make_shared<std::thread>(&AMQPAbstractPublishNotifier::SpawnProtonContainer, this);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
LogPrint("amqp", "amqp: initialization error: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
mapPublishNotifiers.insert(std::make_pair(address, this));
|
||||
} else {
|
||||
// copy the shared ptrs to the message handler and the thread where the proton container is running
|
||||
handler_ = i->second->handler_;
|
||||
thread_ = i->second->thread_;
|
||||
mapPublishNotifiers.insert(std::make_pair(address, this));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AMQPAbstractPublishNotifier::Shutdown()
|
||||
{
|
||||
LogPrint("amqp", "amqp: Shutdown notifier %s at %s\n", GetType(), GetAddress());
|
||||
|
||||
int count = mapPublishNotifiers.count(address);
|
||||
|
||||
// remove this notifier from the list of publishers using this address
|
||||
typedef std::multimap<std::string, AMQPAbstractPublishNotifier*>::iterator iterator;
|
||||
std::pair<iterator, iterator> iterpair = mapPublishNotifiers.equal_range(address);
|
||||
|
||||
for (iterator it = iterpair.first; it != iterpair.second; ++it) {
|
||||
if (it->second == this) {
|
||||
mapPublishNotifiers.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// terminate the connection if this is the last publisher using this address
|
||||
if (count == 1) {
|
||||
handler_->terminate();
|
||||
if (thread_.get() != nullptr) {
|
||||
if (thread_->joinable()) {
|
||||
thread_->join();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool AMQPAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size)
|
||||
{
|
||||
try {
|
||||
proton::binary content;
|
||||
const char *p = (const char *)data;
|
||||
content.assign(p, p + size);
|
||||
|
||||
proton::message message(content);
|
||||
message.subject(std::string(command));
|
||||
proton::message::property_map & props = message.properties();
|
||||
props.put("x-opt-sequence-number", sequence_);
|
||||
handler_->publish(message);
|
||||
|
||||
} catch (proton::error_condition &e) {
|
||||
LogPrint("amqp", "amqp: error : %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
catch (const std::runtime_error &e) {
|
||||
LogPrint("amqp", "amqp: runtime error: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
LogPrint("amqp", "amqp: exception: %s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
catch (...) {
|
||||
LogPrint("amqp", "amqp: unknown error\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
sequence_++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AMQPPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
|
||||
{
|
||||
uint256 hash = pindex->GetBlockHash();
|
||||
LogPrint("amqp", "amqp: Publish hashblock %s\n", hash.GetHex());
|
||||
char data[32];
|
||||
for (unsigned int i = 0; i < 32; i++)
|
||||
data[31 - i] = hash.begin()[i];
|
||||
return SendMessage(MSG_HASHBLOCK, data, 32);
|
||||
}
|
||||
|
||||
bool AMQPPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
|
||||
{
|
||||
uint256 hash = transaction.GetHash();
|
||||
LogPrint("amqp", "amqp: Publish hashtx %s\n", hash.GetHex());
|
||||
char data[32];
|
||||
for (unsigned int i = 0; i < 32; i++)
|
||||
data[31 - i] = hash.begin()[i];
|
||||
return SendMessage(MSG_HASHTX, data, 32);
|
||||
}
|
||||
|
||||
bool AMQPPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
|
||||
{
|
||||
LogPrint("amqp", "amqp: Publish rawblock %s\n", pindex->GetBlockHash().GetHex());
|
||||
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlock block;
|
||||
if(!ReadBlockFromDisk(block, pindex)) {
|
||||
LogPrint("amqp", "amqp: Can't read block from disk");
|
||||
return false;
|
||||
}
|
||||
|
||||
ss << block;
|
||||
}
|
||||
|
||||
return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
|
||||
}
|
||||
|
||||
bool AMQPPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
|
||||
{
|
||||
uint256 hash = transaction.GetHash();
|
||||
LogPrint("amqp", "amqp: Publish rawtx %s\n", hash.GetHex());
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << transaction;
|
||||
return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size());
|
||||
}
|
||||
56
src/amqp/amqppublishnotifier.h
Normal file
56
src/amqp/amqppublishnotifier.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef ZCASH_AMQP_AMQPPUBLISHNOTIFIER_H
|
||||
#define ZCASH_AMQP_AMQPPUBLISHNOTIFIER_H
|
||||
|
||||
#include "amqpabstractnotifier.h"
|
||||
#include "amqpconfig.h"
|
||||
#include "amqpsender.h"
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
class CBlockIndex;
|
||||
|
||||
class AMQPAbstractPublishNotifier : public AMQPAbstractNotifier
|
||||
{
|
||||
private:
|
||||
uint64_t sequence_; // memory only, per notifier instance: upcounting message sequence number
|
||||
|
||||
std::shared_ptr<std::thread> thread_; // proton container thread, may be shared between notifiers
|
||||
std::shared_ptr<AMQPSender> handler_; // proton container message handler, may be shared between notifiers
|
||||
|
||||
public:
|
||||
bool SendMessage(const char *command, const void* data, size_t size);
|
||||
bool Initialize();
|
||||
void Shutdown();
|
||||
void SpawnProtonContainer();
|
||||
};
|
||||
|
||||
class AMQPPublishHashBlockNotifier : public AMQPAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyBlock(const CBlockIndex *pindex);
|
||||
};
|
||||
|
||||
class AMQPPublishHashTransactionNotifier : public AMQPAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyTransaction(const CTransaction &transaction);
|
||||
};
|
||||
|
||||
class AMQPPublishRawBlockNotifier : public AMQPAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyBlock(const CBlockIndex *pindex);
|
||||
};
|
||||
|
||||
class AMQPPublishRawTransactionNotifier : public AMQPAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyTransaction(const CTransaction &transaction);
|
||||
};
|
||||
|
||||
#endif // ZCASH_AMQP_AMQPPUBLISHNOTIFIER_H
|
||||
115
src/amqp/amqpsender.h
Normal file
115
src/amqp/amqpsender.h
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2017 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef ZCASH_AMQP_AMQPSENDER_H
|
||||
#define ZCASH_AMQP_AMQPSENDER_H
|
||||
|
||||
#include "amqpconfig.h"
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
|
||||
class AMQPSender : public proton::messaging_handler {
|
||||
private:
|
||||
std::deque<proton::message> messages_;
|
||||
proton::url url_;
|
||||
proton::connection conn_;
|
||||
proton::sender sender_;
|
||||
std::mutex lock_;
|
||||
std::atomic<bool> terminated_ = {false};
|
||||
|
||||
public:
|
||||
|
||||
AMQPSender(const std::string& url) : url_(url) {}
|
||||
|
||||
// Callback to initialize the container when run() is invoked
|
||||
void on_container_start(proton::container& c) override {
|
||||
proton::duration t(10000); // milliseconds
|
||||
proton::connection_options opts = proton::connection_options().idle_timeout(t);
|
||||
conn_ = c.connect(url_, opts);
|
||||
sender_ = conn_.open_sender(url_.path());
|
||||
}
|
||||
|
||||
// Remote end signals when the local end can send (i.e. has credit)
|
||||
void on_sendable(proton::sender &s) override {
|
||||
dispatch();
|
||||
}
|
||||
|
||||
// Publish message by adding to queue and trying to dispatch it
|
||||
void publish(const proton::message &m) {
|
||||
add_message(m);
|
||||
dispatch();
|
||||
}
|
||||
|
||||
// Add message to queue
|
||||
void add_message(const proton::message &m) {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
messages_.push_back(m);
|
||||
}
|
||||
|
||||
// Send messages in queue
|
||||
void dispatch() {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
|
||||
if (isTerminated()) {
|
||||
throw std::runtime_error("amqp connection was terminated");
|
||||
}
|
||||
|
||||
if (!conn_.active()) {
|
||||
throw std::runtime_error("amqp connection is not active");
|
||||
}
|
||||
|
||||
while (messages_.size() > 0) {
|
||||
if (sender_.credit()) {
|
||||
const proton::message& m = messages_.front();
|
||||
sender_.send(m);
|
||||
messages_.pop_front();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close connection to remote end. Container event-loop, by default, will auto-stop.
|
||||
void terminate() {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
conn_.close();
|
||||
terminated_.store(true);
|
||||
}
|
||||
|
||||
bool isTerminated() const {
|
||||
return terminated_.load();
|
||||
}
|
||||
|
||||
void on_transport_error(proton::transport &t) override {
|
||||
t.connection().close();
|
||||
throw t.error();
|
||||
}
|
||||
|
||||
void on_connection_error(proton::connection &c) override {
|
||||
c.close();
|
||||
throw c.error();
|
||||
}
|
||||
|
||||
void on_session_error(proton::session &s) override {
|
||||
s.connection().close();
|
||||
throw s.error();
|
||||
}
|
||||
|
||||
void on_receiver_error(proton::receiver &r) override {
|
||||
r.connection().close();
|
||||
throw r.error();
|
||||
}
|
||||
|
||||
void on_sender_error(proton::sender &s) override {
|
||||
s.connection().close();
|
||||
throw s.error();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //ZCASH_AMQP_AMQPSENDER_H
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
source pubkey.txt
|
||||
args=("$@")
|
||||
seed_ip=`getent hosts seed.mewhub.com | awk '{ print $1 }'`
|
||||
seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'`
|
||||
komodo_binary='./komodod'
|
||||
delay=20
|
||||
|
||||
@@ -35,11 +35,9 @@ komodo_asset JUMBLR 999999
|
||||
komodo_asset BET 999999
|
||||
komodo_asset CRYPTO 999999
|
||||
komodo_asset HODL 9999999
|
||||
#komodo_asset SHARK 1401
|
||||
komodo_asset MSHARK 1400000
|
||||
komodo_asset BOTS 999999
|
||||
komodo_asset MGW 999999
|
||||
#komodo_asset MVP 1000000
|
||||
komodo_asset COQUI 72000000
|
||||
komodo_asset WLC 210000000
|
||||
komodo_asset KV 1000000
|
||||
@@ -49,37 +47,11 @@ komodo_asset MNZ 257142858
|
||||
komodo_asset AXO 200000000
|
||||
komodo_asset ETOMIC 100000000
|
||||
komodo_asset BTCH 20998641
|
||||
komodo_asset VOTE 49999999999
|
||||
|
||||
#komodo_asset USD
|
||||
#komodo_asset EUR
|
||||
#komodo_asset JPY
|
||||
#komodo_asset GBP
|
||||
#komodo_asset AUD
|
||||
#komodo_asset CAD
|
||||
#komodo_asset CHF
|
||||
#komodo_asset NZD
|
||||
#komodo_asset CNY
|
||||
#komodo_asset RUB
|
||||
#komodo_asset MXN
|
||||
#komodo_asset BRL
|
||||
#komodo_asset INR
|
||||
#komodo_asset HKD
|
||||
#komodo_asset TRY
|
||||
#komodo_asset ZAR
|
||||
#komodo_asset PLN
|
||||
#komodo_asset NOK
|
||||
#komodo_asset SEK
|
||||
#komodo_asset DKK
|
||||
#komodo_asset CZK
|
||||
#komodo_asset HUF
|
||||
#komodo_asset ILS
|
||||
#komodo_asset KRW
|
||||
#komodo_asset MYR
|
||||
#komodo_asset PHP
|
||||
#komodo_asset RON
|
||||
#komodo_asset SGD
|
||||
#komodo_asset THB
|
||||
#komodo_asset BGN
|
||||
#komodo_asset IDR
|
||||
#komodo_asset HRK
|
||||
komodo_asset VOTE2018 600000000
|
||||
komodo_asset PIZZA 100000000
|
||||
komodo_asset BEER 100000000
|
||||
komodo_asset NINJA 100000000
|
||||
komodo_asset OOT 216000000
|
||||
komodo_asset BNTN 500000000
|
||||
komodo_asset CHAIN 999999
|
||||
komodo_asset PRLPAY 500000000
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash
|
||||
set -x
|
||||
delay=60
|
||||
source pubkey.txt
|
||||
@@ -24,9 +24,14 @@ echo $pubkey
|
||||
./komodod -pubkey=$pubkey -ac_name=AXO -ac_supply=200000000 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=VOTE -ac_supply=49999999999 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=24.54.206.138 &
|
||||
./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=24.54.206.138 &
|
||||
./komodod -pubkey=$pubkey -ac_name=VOTE2018 -ac_supply=600000000 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=78.47.196.146 &
|
||||
./komodod -pubkey=$pubkey -ac_name=OOT -ac_supply=216000000 -addnode=174.138.107.226 &
|
||||
./komodod -pubkey=$pubkey -ac_name=BNTN -ac_supply=500000000 -addnode=94.130.169.205 &
|
||||
./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 &
|
||||
./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 &
|
||||
#sleep $delay
|
||||
|
||||
#./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 &
|
||||
|
||||
@@ -24,7 +24,7 @@ using namespace std;
|
||||
*
|
||||
* To subclass AsyncRPCOperation, implement the main() method.
|
||||
* Update the operation status as work is underway and completes.
|
||||
* If main() can be interrupted, inmplement the cancel() method.
|
||||
* If main() can be interrupted, implement the cancel() method.
|
||||
*/
|
||||
|
||||
typedef std::string AsyncRPCOperationId;
|
||||
|
||||
@@ -323,67 +323,60 @@ bool CBitcoinSecret::SetString(const std::string& strSecret)
|
||||
return SetString(strSecret.c_str());
|
||||
}
|
||||
|
||||
bool CZCPaymentAddress::Set(const libzcash::PaymentAddress& addr)
|
||||
template<class DATA_TYPE, CChainParams::Base58Type PREFIX, size_t SER_SIZE>
|
||||
bool CZCEncoding<DATA_TYPE, PREFIX, SER_SIZE>::Set(const DATA_TYPE& addr)
|
||||
{
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << addr;
|
||||
std::vector<unsigned char> addrSerialized(ss.begin(), ss.end());
|
||||
assert(addrSerialized.size() == libzcash::SerializedPaymentAddressSize);
|
||||
SetData(Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS), &addrSerialized[0], libzcash::SerializedPaymentAddressSize);
|
||||
assert(addrSerialized.size() == SER_SIZE);
|
||||
SetData(Params().Base58Prefix(PREFIX), &addrSerialized[0], SER_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
libzcash::PaymentAddress CZCPaymentAddress::Get() const
|
||||
template<class DATA_TYPE, CChainParams::Base58Type PREFIX, size_t SER_SIZE>
|
||||
DATA_TYPE CZCEncoding<DATA_TYPE, PREFIX, SER_SIZE>::Get() const
|
||||
{
|
||||
if (vchData.size() != libzcash::SerializedPaymentAddressSize) {
|
||||
if (vchData.size() != SER_SIZE) {
|
||||
throw std::runtime_error(
|
||||
"payment address is invalid"
|
||||
PrependName(" is invalid")
|
||||
);
|
||||
}
|
||||
|
||||
if (vchVersion != Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS)) {
|
||||
if (vchVersion != Params().Base58Prefix(PREFIX)) {
|
||||
throw std::runtime_error(
|
||||
"payment address is for wrong network type"
|
||||
PrependName(" is for wrong network type")
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> serialized(vchData.begin(), vchData.end());
|
||||
|
||||
CDataStream ss(serialized, SER_NETWORK, PROTOCOL_VERSION);
|
||||
libzcash::PaymentAddress ret;
|
||||
DATA_TYPE ret;
|
||||
ss >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CZCSpendingKey::Set(const libzcash::SpendingKey& addr)
|
||||
{
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << addr;
|
||||
std::vector<unsigned char> addrSerialized(ss.begin(), ss.end());
|
||||
assert(addrSerialized.size() == libzcash::SerializedSpendingKeySize);
|
||||
SetData(Params().Base58Prefix(CChainParams::ZCSPENDING_KEY), &addrSerialized[0], libzcash::SerializedSpendingKeySize);
|
||||
return true;
|
||||
}
|
||||
// Explicit instantiations for libzcash::PaymentAddress
|
||||
template bool CZCEncoding<libzcash::PaymentAddress,
|
||||
CChainParams::ZCPAYMENT_ADDRRESS,
|
||||
libzcash::SerializedPaymentAddressSize>::Set(const libzcash::PaymentAddress& addr);
|
||||
template libzcash::PaymentAddress CZCEncoding<libzcash::PaymentAddress,
|
||||
CChainParams::ZCPAYMENT_ADDRRESS,
|
||||
libzcash::SerializedPaymentAddressSize>::Get() const;
|
||||
|
||||
libzcash::SpendingKey CZCSpendingKey::Get() const
|
||||
{
|
||||
if (vchData.size() != libzcash::SerializedSpendingKeySize) {
|
||||
throw std::runtime_error(
|
||||
"spending key is invalid"
|
||||
);
|
||||
}
|
||||
|
||||
if (vchVersion != Params().Base58Prefix(CChainParams::ZCSPENDING_KEY)) {
|
||||
throw std::runtime_error(
|
||||
"spending key is for wrong network type"
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> serialized(vchData.begin(), vchData.end());
|
||||
|
||||
CDataStream ss(serialized, SER_NETWORK, PROTOCOL_VERSION);
|
||||
libzcash::SpendingKey ret;
|
||||
ss >> ret;
|
||||
return ret;
|
||||
}
|
||||
// Explicit instantiations for libzcash::ViewingKey
|
||||
template bool CZCEncoding<libzcash::ViewingKey,
|
||||
CChainParams::ZCVIEWING_KEY,
|
||||
libzcash::SerializedViewingKeySize>::Set(const libzcash::ViewingKey& vk);
|
||||
template libzcash::ViewingKey CZCEncoding<libzcash::ViewingKey,
|
||||
CChainParams::ZCVIEWING_KEY,
|
||||
libzcash::SerializedViewingKeySize>::Get() const;
|
||||
|
||||
// Explicit instantiations for libzcash::SpendingKey
|
||||
template bool CZCEncoding<libzcash::SpendingKey,
|
||||
CChainParams::ZCSPENDING_KEY,
|
||||
libzcash::SerializedSpendingKeySize>::Set(const libzcash::SpendingKey& sk);
|
||||
template libzcash::SpendingKey CZCEncoding<libzcash::SpendingKey,
|
||||
CChainParams::ZCSPENDING_KEY,
|
||||
libzcash::SerializedSpendingKeySize>::Get() const;
|
||||
|
||||
40
src/base58.h
40
src/base58.h
@@ -96,26 +96,48 @@ public:
|
||||
bool operator> (const CBase58Data& b58) const { return CompareTo(b58) > 0; }
|
||||
};
|
||||
|
||||
class CZCPaymentAddress : public CBase58Data {
|
||||
template<class DATA_TYPE, CChainParams::Base58Type PREFIX, size_t SER_SIZE>
|
||||
class CZCEncoding : public CBase58Data {
|
||||
protected:
|
||||
virtual std::string PrependName(const std::string& s) const = 0;
|
||||
|
||||
public:
|
||||
bool Set(const DATA_TYPE& addr);
|
||||
|
||||
DATA_TYPE Get() const;
|
||||
};
|
||||
|
||||
class CZCPaymentAddress : public CZCEncoding<libzcash::PaymentAddress, CChainParams::ZCPAYMENT_ADDRRESS, libzcash::SerializedPaymentAddressSize> {
|
||||
protected:
|
||||
std::string PrependName(const std::string& s) const { return "payment address" + s; }
|
||||
|
||||
public:
|
||||
bool Set(const libzcash::PaymentAddress& addr);
|
||||
CZCPaymentAddress() {}
|
||||
|
||||
CZCPaymentAddress(const std::string& strAddress) { SetString(strAddress.c_str(), 2); }
|
||||
CZCPaymentAddress(const libzcash::PaymentAddress& addr) { Set(addr); }
|
||||
|
||||
libzcash::PaymentAddress Get() const;
|
||||
};
|
||||
|
||||
class CZCSpendingKey : public CBase58Data {
|
||||
class CZCViewingKey : public CZCEncoding<libzcash::ViewingKey, CChainParams::ZCVIEWING_KEY, libzcash::SerializedViewingKeySize> {
|
||||
protected:
|
||||
std::string PrependName(const std::string& s) const { return "viewing key" + s; }
|
||||
|
||||
public:
|
||||
CZCViewingKey() {}
|
||||
|
||||
CZCViewingKey(const std::string& strViewingKey) { SetString(strViewingKey.c_str(), 3); }
|
||||
CZCViewingKey(const libzcash::ViewingKey& vk) { Set(vk); }
|
||||
};
|
||||
|
||||
class CZCSpendingKey : public CZCEncoding<libzcash::SpendingKey, CChainParams::ZCSPENDING_KEY, libzcash::SerializedSpendingKeySize> {
|
||||
protected:
|
||||
std::string PrependName(const std::string& s) const { return "spending key" + s; }
|
||||
|
||||
public:
|
||||
bool Set(const libzcash::SpendingKey& addr);
|
||||
CZCSpendingKey() {}
|
||||
|
||||
CZCSpendingKey(const std::string& strAddress) { SetString(strAddress.c_str(), 2); }
|
||||
CZCSpendingKey(const libzcash::SpendingKey& addr) { Set(addr); }
|
||||
|
||||
libzcash::SpendingKey Get() const;
|
||||
};
|
||||
|
||||
/** base58-encoded Bitcoin addresses.
|
||||
@@ -172,7 +194,7 @@ public:
|
||||
K GetKey() {
|
||||
K ret;
|
||||
if (vchData.size() == Size) {
|
||||
//if base58 encouded data not holds a ext key, return a !IsValid() key
|
||||
//if base58 encoded data not holds a ext key, return a !IsValid() key
|
||||
ret.Decode(&vchData[0]);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#define FROM_CLI
|
||||
#include "uint256.h"
|
||||
#include "arith_uint256.h"
|
||||
|
||||
@@ -75,16 +76,16 @@ public:
|
||||
#include "komodo_cJSON.c"
|
||||
#include "komodo_notary.h"
|
||||
|
||||
uint32_t komodo_heightstamp(int32_t height)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint32_t komodo_heightstamp(int32_t height)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
static bool AppInitRPC(int argc, char* argv[])
|
||||
{
|
||||
//
|
||||
|
||||
@@ -20,14 +20,6 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <float.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
|
||||
139
src/cc/betprotocol.cpp
Normal file
139
src/cc/betprotocol.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include <cryptoconditions.h>
|
||||
|
||||
#include "streams.h"
|
||||
#include "script/cc.h"
|
||||
#include "cc/eval.h"
|
||||
#include "cc/betprotocol.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
|
||||
std::vector<CC*> BetProtocol::PlayerConditions()
|
||||
{
|
||||
std::vector<CC*> subs;
|
||||
for (int i=0; i<players.size(); i++)
|
||||
subs.push_back(CCNewSecp256k1(players[i]));
|
||||
return subs;
|
||||
}
|
||||
|
||||
|
||||
CC* BetProtocol::MakeDisputeCond()
|
||||
{
|
||||
CC *disputePoker = CCNewEval(E_MARSHAL(
|
||||
ss << disputeCode << VARINT(waitBlocks) << vmParams;
|
||||
));
|
||||
|
||||
CC *anySig = CCNewThreshold(1, PlayerConditions());
|
||||
|
||||
return CCNewThreshold(2, {disputePoker, anySig});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* spendFee is the amount assigned to each output, for the purposes of posting
|
||||
* dispute / evidence.
|
||||
*/
|
||||
CMutableTransaction BetProtocol::MakeSessionTx(CAmount spendFee)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
|
||||
CC *disputeCond = MakeDisputeCond();
|
||||
mtx.vout.push_back(CTxOut(spendFee, CCPubKey(disputeCond)));
|
||||
cc_free(disputeCond);
|
||||
|
||||
for (int i=0; i<players.size(); i++) {
|
||||
CC *cond = CCNewSecp256k1(players[i]);
|
||||
mtx.vout.push_back(CTxOut(spendFee, CCPubKey(cond)));
|
||||
cc_free(cond);
|
||||
}
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
CMutableTransaction BetProtocol::MakeDisputeTx(uint256 signedSessionTxHash, uint256 vmResultHash)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
|
||||
CC *disputeCond = MakeDisputeCond();
|
||||
mtx.vin.push_back(CTxIn(signedSessionTxHash, 0, CScript()));
|
||||
|
||||
std::vector<unsigned char> result(vmResultHash.begin(), vmResultHash.begin()+32);
|
||||
mtx.vout.push_back(CTxOut(0, CScript() << OP_RETURN << result));
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
CMutableTransaction BetProtocol::MakePostEvidenceTx(uint256 signedSessionTxHash,
|
||||
int playerIdx, std::vector<unsigned char> state)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
|
||||
mtx.vin.push_back(CTxIn(signedSessionTxHash, playerIdx+1, CScript()));
|
||||
mtx.vout.push_back(CTxOut(0, CScript() << OP_RETURN << state));
|
||||
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
CC* BetProtocol::MakePayoutCond(uint256 signedSessionTxHash)
|
||||
{
|
||||
// TODO: 2/3 majority
|
||||
CC* agree = CCNewThreshold(players.size(), PlayerConditions());
|
||||
|
||||
CC *import;
|
||||
{
|
||||
CC *importEval = CCNewEval(E_MARSHAL(
|
||||
ss << EVAL_IMPORTPAYOUT << signedSessionTxHash;
|
||||
));
|
||||
|
||||
CC *oneof = CCNewThreshold(1, PlayerConditions());
|
||||
|
||||
import = CCNewThreshold(2, {oneof, importEval});
|
||||
}
|
||||
|
||||
return CCNewThreshold(1, {agree, import});
|
||||
}
|
||||
|
||||
|
||||
CMutableTransaction BetProtocol::MakeStakeTx(CAmount totalPayout, uint256 signedSessionTxHash)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
|
||||
CC *payoutCond = MakePayoutCond(signedSessionTxHash);
|
||||
mtx.vout.push_back(CTxOut(totalPayout, CCPubKey(payoutCond)));
|
||||
cc_free(payoutCond);
|
||||
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
CMutableTransaction BetProtocol::MakeAgreePayoutTx(std::vector<CTxOut> payouts,
|
||||
uint256 signedStakeTxHash)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
mtx.vin.push_back(CTxIn(signedStakeTxHash, 0, CScript()));
|
||||
mtx.vout = payouts;
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
CMutableTransaction BetProtocol::MakeImportPayoutTx(std::vector<CTxOut> payouts,
|
||||
CTransaction signedDisputeTx, uint256 signedStakeTxHash, MoMProof momProof)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
mtx.vin.push_back(CTxIn(signedStakeTxHash, 0, CScript()));
|
||||
mtx.vout = payouts;
|
||||
CScript proofData;
|
||||
proofData << OP_RETURN << E_MARSHAL(ss << momProof << signedDisputeTx);
|
||||
mtx.vout.insert(mtx.vout.begin(), CTxOut(0, proofData));
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
bool GetOpReturnHash(CScript script, uint256 &hash)
|
||||
{
|
||||
std::vector<unsigned char> vHash;
|
||||
GetOpReturnData(script, vHash);
|
||||
if (vHash.size() != 32) return false;
|
||||
hash = uint256(vHash);
|
||||
return true;
|
||||
}
|
||||
68
src/cc/betprotocol.h
Normal file
68
src/cc/betprotocol.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef BETPROTOCOL_H
|
||||
#define BETPROTOCOL_H
|
||||
|
||||
#include "cc/eval.h"
|
||||
#include "pubkey.h"
|
||||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "cryptoconditions/include/cryptoconditions.h"
|
||||
|
||||
|
||||
class MoMProof
|
||||
{
|
||||
public:
|
||||
int nIndex;
|
||||
std::vector<uint256> branch;
|
||||
uint256 notarisationHash;
|
||||
|
||||
MoMProof() {}
|
||||
MoMProof(int i, std::vector<uint256> b, uint256 n) : notarisationHash(n), nIndex(i), branch(b) {}
|
||||
uint256 Exec(uint256 hash) const { return CBlock::CheckMerkleBranch(hash, branch, nIndex); }
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
READWRITE(VARINT(nIndex));
|
||||
READWRITE(branch);
|
||||
READWRITE(notarisationHash);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class BetProtocol
|
||||
{
|
||||
protected:
|
||||
std::vector<CC*> playerConditions();
|
||||
public:
|
||||
EvalCode disputeCode;
|
||||
std::vector<CPubKey> players;
|
||||
std::vector<unsigned char> vmParams;
|
||||
uint32_t waitBlocks;
|
||||
|
||||
// Utility
|
||||
BetProtocol(EvalCode dc, std::vector<CPubKey> ps, uint32_t wb, std::vector<uint8_t> vmp)
|
||||
: disputeCode(dc), waitBlocks(wb), vmParams(vmp), players(ps) {}
|
||||
std::vector<CC*> PlayerConditions();
|
||||
|
||||
// on PANGEA
|
||||
CC* MakeDisputeCond();
|
||||
CMutableTransaction MakeSessionTx(CAmount spendFee);
|
||||
CMutableTransaction MakeDisputeTx(uint256 signedSessionTxHash, uint256 vmResultHash);
|
||||
CMutableTransaction MakePostEvidenceTx(uint256 signedSessionTxHash,
|
||||
int playerIndex, std::vector<unsigned char> state);
|
||||
|
||||
// on KMD
|
||||
CC* MakePayoutCond(uint256 signedSessionTxHash);
|
||||
CMutableTransaction MakeStakeTx(CAmount totalPayout, uint256 signedSessionTx);
|
||||
CMutableTransaction MakeAgreePayoutTx(std::vector<CTxOut> payouts, uint256 signedStakeTxHash);
|
||||
CMutableTransaction MakeImportPayoutTx(std::vector<CTxOut> payouts,
|
||||
CTransaction signedDisputeTx, uint256 signedStakeTxHash, MoMProof momProof);
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool GetOpReturnHash(CScript script, uint256 &hash);
|
||||
|
||||
|
||||
#endif /* BETPROTOCOL_H */
|
||||
84
src/cc/disputepayout.cpp
Normal file
84
src/cc/disputepayout.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <cryptoconditions.h>
|
||||
|
||||
#include "hash.h"
|
||||
#include "chain.h"
|
||||
#include "version.h"
|
||||
#include "script/cc.h"
|
||||
#include "cc/eval.h"
|
||||
#include "cc/betprotocol.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
|
||||
/*
|
||||
* Crypto-Condition EVAL method that resolves a dispute of a session
|
||||
*
|
||||
* IN: vm - AppVM virtual machine to verify states
|
||||
* IN: params - condition params
|
||||
* IN: disputeTx - transaction attempting to resolve dispute
|
||||
* IN: nIn - index of input of dispute tx
|
||||
*
|
||||
* disputeTx: attempt to resolve a dispute
|
||||
*
|
||||
* in 0: Spends Session TX first output, reveals DisputeHeader
|
||||
* out 0: OP_RETURN hash of payouts
|
||||
*/
|
||||
bool Eval::DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransaction &disputeTx, unsigned int nIn)
|
||||
{
|
||||
if (disputeTx.vout.size() == 0) return Invalid("no-vouts");
|
||||
|
||||
// get payouts hash
|
||||
uint256 payoutHash;
|
||||
if (!GetOpReturnHash(disputeTx.vout[0].scriptPubKey, payoutHash))
|
||||
return Invalid("invalid-payout-hash");
|
||||
|
||||
// load params
|
||||
uint16_t waitBlocks;
|
||||
std::vector<uint8_t> vmParams;
|
||||
if (!E_UNMARSHAL(params, ss >> VARINT(waitBlocks); ss >> vmParams))
|
||||
return Invalid("malformed-params");
|
||||
|
||||
// ensure that enough time has passed
|
||||
{
|
||||
CTransaction sessionTx;
|
||||
CBlockIndex sessionBlock;
|
||||
|
||||
// if unconformed its too soon
|
||||
if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock))
|
||||
return Error("couldnt-get-parent");
|
||||
|
||||
if (GetCurrentHeight() < sessionBlock.nHeight + waitBlocks)
|
||||
return Invalid("dispute-too-soon"); // Not yet
|
||||
}
|
||||
|
||||
// get spends
|
||||
std::vector<CTransaction> spends;
|
||||
if (!GetSpendsConfirmed(disputeTx.vin[0].prevout.hash, spends))
|
||||
return Error("couldnt-get-spends");
|
||||
|
||||
// verify result from VM
|
||||
int maxLength = -1;
|
||||
uint256 bestPayout;
|
||||
for (int i=1; i<spends.size(); i++)
|
||||
{
|
||||
std::vector<unsigned char> vmState;
|
||||
if (spends[i].vout.size() == 0) continue;
|
||||
if (!GetOpReturnData(spends[i].vout[0].scriptPubKey, vmState)) continue;
|
||||
auto out = vm.evaluate(vmParams, vmState);
|
||||
uint256 resultHash = SerializeHash(out.second);
|
||||
if (out.first > maxLength) {
|
||||
maxLength = out.first;
|
||||
bestPayout = resultHash;
|
||||
}
|
||||
// The below means that if for any reason there is a draw, the first dispute wins
|
||||
else if (out.first == maxLength) {
|
||||
if (bestPayout != payoutHash) {
|
||||
fprintf(stderr, "WARNING: VM has multiple solutions of same length\n");
|
||||
bestPayout = resultHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLength == -1) return Invalid("no-evidence");
|
||||
|
||||
return bestPayout == payoutHash ? Valid() : Invalid("wrong-payout");
|
||||
}
|
||||
205
src/cc/eval.cpp
Normal file
205
src/cc/eval.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
#include <assert.h>
|
||||
#include <cryptoconditions.h>
|
||||
|
||||
#include "primitives/transaction.h"
|
||||
#include "script/cc.h"
|
||||
#include "cc/eval.h"
|
||||
#include "main.h"
|
||||
#include "chain.h"
|
||||
#include "core_io.h"
|
||||
|
||||
|
||||
Eval* EVAL_TEST = 0;
|
||||
|
||||
|
||||
bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn)
|
||||
{
|
||||
Eval eval_;
|
||||
Eval *eval = EVAL_TEST;
|
||||
if (!eval) eval = &eval_;
|
||||
|
||||
bool out = eval->Dispatch(cond, tx, nIn);
|
||||
assert(eval->state.IsValid() == out);
|
||||
|
||||
if (eval->state.IsValid()) return true;
|
||||
|
||||
std::string lvl = eval->state.IsInvalid() ? "Invalid" : "Error!";
|
||||
fprintf(stderr, "CC Eval %s %s: %s spending tx %s\n",
|
||||
EvalToStr(cond->code[0]).data(),
|
||||
lvl.data(),
|
||||
eval->state.GetRejectReason().data(),
|
||||
tx.vin[nIn].prevout.hash.GetHex().data());
|
||||
if (eval->state.IsError()) fprintf(stderr, "Culprit: %s\n", EncodeHexTx(tx).data());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test the validity of an Eval node
|
||||
*/
|
||||
bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn)
|
||||
{
|
||||
if (cond->codeLength == 0)
|
||||
return Invalid("empty-eval");
|
||||
|
||||
uint8_t ecode = cond->code[0];
|
||||
std::vector<uint8_t> vparams(cond->code+1, cond->code+cond->codeLength);
|
||||
|
||||
if (ecode == EVAL_IMPORTPAYOUT) {
|
||||
return ImportPayout(vparams, txTo, nIn);
|
||||
}
|
||||
|
||||
return Invalid("invalid-code");
|
||||
}
|
||||
|
||||
|
||||
bool Eval::GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) const
|
||||
{
|
||||
// NOT IMPLEMENTED
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
|
||||
{
|
||||
bool fAllowSlow = false; // Don't allow slow
|
||||
return GetTransaction(hash, txOut, hashBlock, fAllowSlow);
|
||||
}
|
||||
|
||||
|
||||
bool Eval::GetTxConfirmed(const uint256 &hash, CTransaction &txOut, CBlockIndex &block) const
|
||||
{
|
||||
uint256 hashBlock;
|
||||
if (!GetTxUnconfirmed(hash, txOut, hashBlock))
|
||||
return false;
|
||||
if (hashBlock.IsNull() || !GetBlock(hashBlock, block))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Eval::GetCurrentHeight() const
|
||||
{
|
||||
return chainActive.Height();
|
||||
}
|
||||
|
||||
|
||||
bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
||||
{
|
||||
auto r = mapBlockIndex.find(hash);
|
||||
if (r != mapBlockIndex.end()) {
|
||||
blockIdx = *r->second;
|
||||
return true;
|
||||
}
|
||||
fprintf(stderr, "CC Eval Error: Can't get block from index\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
||||
|
||||
|
||||
int32_t Eval::GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const
|
||||
{
|
||||
return komodo_notaries(pubkeys, height, timestamp);
|
||||
}
|
||||
|
||||
|
||||
bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const
|
||||
{
|
||||
if (tx.vin.size() < 11) return false;
|
||||
|
||||
uint8_t seenNotaries[64] = {0};
|
||||
uint8_t notaries[64][33];
|
||||
int nNotaries = GetNotaries(notaries, height, timestamp);
|
||||
|
||||
BOOST_FOREACH(const CTxIn &txIn, tx.vin)
|
||||
{
|
||||
// Get notary pubkey
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
if (!GetTxUnconfirmed(txIn.prevout.hash, tx, hashBlock)) return false;
|
||||
if (tx.vout.size() < txIn.prevout.n) return false;
|
||||
CScript spk = tx.vout[txIn.prevout.n].scriptPubKey;
|
||||
if (spk.size() != 35) return false;
|
||||
const unsigned char *pk = spk.data();
|
||||
if (pk++[0] != 33) return false;
|
||||
if (pk[33] != OP_CHECKSIG) return false;
|
||||
|
||||
// Check it's a notary
|
||||
for (int i=0; i<nNotaries; i++) {
|
||||
if (!seenNotaries[i]) {
|
||||
if (memcmp(pk, notaries[i], 33) == 0) {
|
||||
seenNotaries[i] = 1;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
found:;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get MoM from a notarisation tx hash
|
||||
*/
|
||||
bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) const
|
||||
{
|
||||
CTransaction notarisationTx;
|
||||
CBlockIndex block;
|
||||
if (!GetTxConfirmed(notaryHash, notarisationTx, block)) return false;
|
||||
if (!CheckNotaryInputs(notarisationTx, block.nHeight, block.nTime)) return false;
|
||||
if (notarisationTx.vout.size() < 2) return false;
|
||||
if (!data.Parse(notarisationTx.vout[1].scriptPubKey)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Notarisation data, ie, OP_RETURN payload in notarisation transactions
|
||||
*/
|
||||
extern char ASSETCHAINS_SYMBOL[16];
|
||||
|
||||
bool NotarisationData::Parse(const CScript scriptPK)
|
||||
{
|
||||
*this = NotarisationData();
|
||||
|
||||
std::vector<unsigned char> vdata;
|
||||
if (!GetOpReturnData(scriptPK, vdata)) return false;
|
||||
|
||||
CDataStream ss(vdata, SER_NETWORK, PROTOCOL_VERSION);
|
||||
|
||||
try {
|
||||
ss >> blockHash;
|
||||
ss >> height;
|
||||
if (ASSETCHAINS_SYMBOL[0])
|
||||
ss >> txHash;
|
||||
|
||||
char *nullPos = (char*) memchr(&ss[0], 0, ss.size());
|
||||
if (!nullPos) return false;
|
||||
ss.read(symbol, nullPos-&ss[0]+1);
|
||||
|
||||
if (ss.size() < 36) return false;
|
||||
ss >> MoM;
|
||||
ss >> MoMDepth;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Misc
|
||||
*/
|
||||
|
||||
std::string EvalToStr(EvalCode c)
|
||||
{
|
||||
FOREACH_EVAL(EVAL_GENERATE_STRING);
|
||||
char s[10];
|
||||
sprintf(s, "0x%x", c);
|
||||
return std::string(s);
|
||||
}
|
||||
143
src/cc/eval.h
Normal file
143
src/cc/eval.h
Normal file
@@ -0,0 +1,143 @@
|
||||
#ifndef CC_EVAL_H
|
||||
#define CC_EVAL_H
|
||||
|
||||
#include <cryptoconditions.h>
|
||||
|
||||
#include "chain.h"
|
||||
#include "streams.h"
|
||||
#include "version.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
|
||||
/*
|
||||
* Eval codes
|
||||
*
|
||||
* Add to below macro to generate new code.
|
||||
*
|
||||
* If at some point a new interpretation model is introduced,
|
||||
* there should be a code identifying it. For example,
|
||||
* a possible code is EVAL_BITCOIN_SCRIPT, where the entire binary
|
||||
* after the code is interpreted as a bitcoin script.
|
||||
*/
|
||||
#define FOREACH_EVAL(EVAL) \
|
||||
EVAL(EVAL_IMPORTPAYOUT, 0xe1)
|
||||
|
||||
typedef uint8_t EvalCode;
|
||||
|
||||
|
||||
class AppVM;
|
||||
class NotarisationData;
|
||||
|
||||
|
||||
class Eval
|
||||
{
|
||||
public:
|
||||
CValidationState state;
|
||||
|
||||
bool Invalid(std::string s) { return state.Invalid(false, 0, s); }
|
||||
bool Error(std::string s) { return state.Error(s); }
|
||||
bool Valid() { return true; }
|
||||
|
||||
/*
|
||||
* Test validity of a CC_Eval node
|
||||
*/
|
||||
virtual bool Dispatch(const CC *cond, const CTransaction &tx, unsigned int nIn);
|
||||
|
||||
/*
|
||||
* Dispute a payout using a VM
|
||||
*/
|
||||
bool DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransaction &disputeTx, unsigned int nIn);
|
||||
|
||||
/*
|
||||
* Test an ImportPayout CC Eval condition
|
||||
*/
|
||||
bool ImportPayout(std::vector<uint8_t> params, const CTransaction &importTx, unsigned int nIn);
|
||||
|
||||
/*
|
||||
* IO functions
|
||||
*/
|
||||
virtual bool GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const;
|
||||
virtual bool GetTxConfirmed(const uint256 &hash, CTransaction &txOut, CBlockIndex &block) const;
|
||||
virtual unsigned int GetCurrentHeight() const;
|
||||
virtual bool GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) const;
|
||||
virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const;
|
||||
virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const;
|
||||
virtual bool GetNotarisationData(uint256 notarisationHash, NotarisationData &data) const;
|
||||
virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const;
|
||||
};
|
||||
|
||||
|
||||
bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn);
|
||||
|
||||
|
||||
/*
|
||||
* Virtual machine to use in the case of on-chain app evaluation
|
||||
*/
|
||||
class AppVM
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* in: header - paramters agreed upon by all players
|
||||
* in: body - gamestate
|
||||
* out: length - length of game (longest wins)
|
||||
* out: payments - vector of CTxOut, always deterministically sorted.
|
||||
*/
|
||||
virtual std::pair<int,std::vector<CTxOut>>
|
||||
evaluate(std::vector<unsigned char> header, std::vector<unsigned char> body) = 0;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Data from notarisation OP_RETURN
|
||||
*/
|
||||
class NotarisationData {
|
||||
public:
|
||||
uint256 blockHash;
|
||||
uint32_t height;
|
||||
uint256 txHash; // Only get this guy in asset chains not in KMD
|
||||
char symbol[64];
|
||||
uint256 MoM;
|
||||
uint32_t MoMDepth;
|
||||
|
||||
bool Parse(CScript scriptPubKey);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Eval code utilities.
|
||||
*/
|
||||
#define EVAL_GENERATE_DEF(L,I) const uint8_t L = I;
|
||||
#define EVAL_GENERATE_STRING(L,I) if (c == I) return #L;
|
||||
|
||||
FOREACH_EVAL(EVAL_GENERATE_DEF);
|
||||
|
||||
std::string EvalToStr(EvalCode c);
|
||||
|
||||
|
||||
/*
|
||||
* Serialisation boilerplate
|
||||
*/
|
||||
#define E_MARSHAL(body) SerializeF([&] (CDataStream &ss) {body;})
|
||||
template <class T>
|
||||
std::vector<uint8_t> SerializeF(const T f)
|
||||
{
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
f(ss);
|
||||
return std::vector<unsigned char>(ss.begin(), ss.end());
|
||||
}
|
||||
|
||||
#define E_UNMARSHAL(params, body) DeserializeF(params, [&] (CDataStream &ss) {body;})
|
||||
template <class T>
|
||||
bool DeserializeF(const std::vector<unsigned char> vIn, T f)
|
||||
{
|
||||
CDataStream ss(vIn, SER_NETWORK, PROTOCOL_VERSION);
|
||||
try {
|
||||
f(ss);
|
||||
if (ss.eof()) return true;
|
||||
} catch(...) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endif /* CC_EVAL_H */
|
||||
76
src/cc/importpayout.cpp
Normal file
76
src/cc/importpayout.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <cryptoconditions.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "chain.h"
|
||||
#include "streams.h"
|
||||
#include "cc/eval.h"
|
||||
#include "cc/betprotocol.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
|
||||
/*
|
||||
* Crypto-Condition EVAL method that verifies a payout against a transaction
|
||||
* notarised on another chain.
|
||||
*
|
||||
* IN: params - condition params
|
||||
* IN: importTx - Payout transaction on value chain (KMD)
|
||||
* IN: nIn - index of input of stake
|
||||
*
|
||||
* importTx: Spends stakeTx with payouts from asset chain
|
||||
*
|
||||
* in 0: Spends Stake TX and contains ImportPayout CC
|
||||
* out 0: OP_RETURN MomProof, disputeTx
|
||||
* out 1-: arbitrary payouts
|
||||
*
|
||||
* disputeTx: Spends sessionTx.0 (opener on asset chain)
|
||||
*
|
||||
* in 0: spends sessionTx.0
|
||||
* in 1-: anything
|
||||
* out 0: OP_RETURN hash of payouts
|
||||
* out 1-: anything
|
||||
*/
|
||||
bool Eval::ImportPayout(const std::vector<uint8_t> params, const CTransaction &importTx, unsigned int nIn)
|
||||
{
|
||||
if (importTx.vout.size() == 0) return Invalid("no-vouts");
|
||||
|
||||
// load data from vout[0]
|
||||
MoMProof proof;
|
||||
CTransaction disputeTx;
|
||||
{
|
||||
std::vector<unsigned char> vopret;
|
||||
GetOpReturnData(importTx.vout[0].scriptPubKey, vopret);
|
||||
if (!E_UNMARSHAL(vopret, ss >> proof; ss >> disputeTx))
|
||||
return Invalid("invalid-payload");
|
||||
}
|
||||
|
||||
// Check disputeTx.0 shows correct payouts
|
||||
{
|
||||
uint256 givenPayoutsHash;
|
||||
GetOpReturnHash(disputeTx.vout[0].scriptPubKey, givenPayoutsHash);
|
||||
std::vector<CTxOut> payouts(importTx.vout.begin() + 1, importTx.vout.end());
|
||||
if (givenPayoutsHash != SerializeHash(payouts))
|
||||
return Invalid("wrong-payouts");
|
||||
}
|
||||
|
||||
// Check disputeTx spends sessionTx.0
|
||||
// condition ImportPayout params is session ID from other chain
|
||||
{
|
||||
uint256 sessionHash;
|
||||
if (!E_UNMARSHAL(params, ss >> sessionHash))
|
||||
return Invalid("malformed-params");
|
||||
if (disputeTx.vin[0].prevout != COutPoint(sessionHash, 0))
|
||||
return Invalid("wrong-session");
|
||||
}
|
||||
|
||||
// Check disputeTx solves momproof from vout[0]
|
||||
{
|
||||
NotarisationData data;
|
||||
if (!GetNotarisationData(proof.notarisationHash, data))
|
||||
return Invalid("coudnt-load-mom");
|
||||
|
||||
if (data.MoM != proof.Exec(disputeTx.GetHash()))
|
||||
return Invalid("mom-check-fail");
|
||||
}
|
||||
|
||||
return Valid();
|
||||
}
|
||||
@@ -81,7 +81,8 @@ CBlockIndex* CBlockIndex::GetAncestor(int height)
|
||||
|
||||
CBlockIndex* pindexWalk = this;
|
||||
int heightWalk = nHeight;
|
||||
while (heightWalk > height) {
|
||||
while ( heightWalk > height && pindexWalk != 0 )
|
||||
{
|
||||
int heightSkip = GetSkipHeight(heightWalk);
|
||||
int heightSkipPrev = GetSkipHeight(heightWalk - 1);
|
||||
if (pindexWalk->pskip != NULL &&
|
||||
|
||||
45
src/chain.h
45
src/chain.h
@@ -16,6 +16,8 @@
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
static const int SPROUT_VALUE_VERSION = 1001400;
|
||||
|
||||
struct CDiskBlockPos
|
||||
{
|
||||
int nFile;
|
||||
@@ -92,8 +94,14 @@ enum BlockStatus: uint32_t {
|
||||
BLOCK_FAILED_VALID = 32, //! stage after last reached validness failed
|
||||
BLOCK_FAILED_CHILD = 64, //! descends from failed block
|
||||
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD,
|
||||
|
||||
BLOCK_ACTIVATES_UPGRADE = 128, //! block activates a network upgrade
|
||||
};
|
||||
|
||||
//! Short-hand for the highest consensus validity we implement.
|
||||
//! Blocks with this validity are assumed to satisfy all consensus rules.
|
||||
static const BlockStatus BLOCK_VALID_CONSENSUS = BLOCK_VALID_SCRIPTS;
|
||||
|
||||
/** The block chain is a tree shaped structure starting with the
|
||||
* genesis block at the root, with each block potentially having multiple
|
||||
* candidates to be the next block. A blockindex may have multiple pprev pointing
|
||||
@@ -138,12 +146,26 @@ public:
|
||||
//! Verification status of this block. See enum BlockStatus
|
||||
unsigned int nStatus;
|
||||
|
||||
//! Branch ID corresponding to the consensus rules used to validate this block.
|
||||
//! Only cached if block validity is BLOCK_VALID_CONSENSUS.
|
||||
//! Persisted at each activation height, memory-only for intervening blocks.
|
||||
boost::optional<uint32_t> nCachedBranchId;
|
||||
|
||||
//! The anchor for the tree state up to the start of this block
|
||||
uint256 hashAnchor;
|
||||
|
||||
//! (memory only) The anchor for the tree state up to the end of this block
|
||||
uint256 hashAnchorEnd;
|
||||
|
||||
//! Change in value held by the Sprout circuit over this block.
|
||||
//! Will be boost::none for older blocks on old nodes until a reindex has taken place.
|
||||
boost::optional<CAmount> nSproutValue;
|
||||
|
||||
//! (memory only) Total value held by the Sprout circuit up to and including this block.
|
||||
//! Will be boost::none for on old nodes until a reindex has taken place.
|
||||
//! Will be boost::none if nChainTx is zero.
|
||||
boost::optional<CAmount> nChainSproutValue;
|
||||
|
||||
//! block header
|
||||
int nVersion;
|
||||
uint256 hashMerkleRoot;
|
||||
@@ -155,7 +177,7 @@ public:
|
||||
|
||||
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
|
||||
uint32_t nSequenceId;
|
||||
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
phashBlock = NULL;
|
||||
@@ -169,9 +191,12 @@ public:
|
||||
nTx = 0;
|
||||
nChainTx = 0;
|
||||
nStatus = 0;
|
||||
nCachedBranchId = boost::none;
|
||||
hashAnchor = uint256();
|
||||
hashAnchorEnd = uint256();
|
||||
nSequenceId = 0;
|
||||
nSproutValue = boost::none;
|
||||
nChainSproutValue = boost::none;
|
||||
|
||||
nVersion = 0;
|
||||
hashMerkleRoot = uint256();
|
||||
@@ -328,6 +353,18 @@ public:
|
||||
READWRITE(VARINT(nDataPos));
|
||||
if (nStatus & BLOCK_HAVE_UNDO)
|
||||
READWRITE(VARINT(nUndoPos));
|
||||
if (nStatus & BLOCK_ACTIVATES_UPGRADE) {
|
||||
if (ser_action.ForRead()) {
|
||||
uint32_t branchId;
|
||||
READWRITE(branchId);
|
||||
nCachedBranchId = branchId;
|
||||
} else {
|
||||
// nCachedBranchId must always be set if BLOCK_ACTIVATES_UPGRADE is set.
|
||||
assert(nCachedBranchId);
|
||||
uint32_t branchId = *nCachedBranchId;
|
||||
READWRITE(branchId);
|
||||
}
|
||||
}
|
||||
READWRITE(hashAnchor);
|
||||
|
||||
// block header
|
||||
@@ -339,6 +376,12 @@ public:
|
||||
READWRITE(nBits);
|
||||
READWRITE(nNonce);
|
||||
READWRITE(nSolution);
|
||||
|
||||
// Only read/write nSproutValue if the client version used to create
|
||||
// this index was storing them.
|
||||
if ((nType & SER_DISK) && (nVersion >= SPROUT_VALUE_VERSION)) {
|
||||
READWRITE(nSproutValue);
|
||||
}
|
||||
}
|
||||
|
||||
uint256 GetBlockHash() const
|
||||
|
||||
@@ -15,10 +15,56 @@
|
||||
|
||||
#include "base58.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "chainparamsseeds.h"
|
||||
|
||||
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, const uint256& nNonce, const std::vector<unsigned char>& nSolution, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
||||
{
|
||||
// To create a genesis block for a new chain which is Overwintered:
|
||||
// txNew.nVersion = 3
|
||||
// txNew.fOverwintered = true
|
||||
// txNew.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID
|
||||
// txNew.nExpiryHeight = <default value>
|
||||
CMutableTransaction txNew;
|
||||
txNew.nVersion = 1;
|
||||
txNew.vin.resize(1);
|
||||
txNew.vout.resize(1);
|
||||
txNew.vin[0].scriptSig = CScript() << 520617983 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
|
||||
txNew.vout[0].nValue = genesisReward;
|
||||
txNew.vout[0].scriptPubKey = genesisOutputScript;
|
||||
|
||||
CBlock genesis;
|
||||
genesis.nTime = nTime;
|
||||
genesis.nBits = nBits;
|
||||
genesis.nNonce = nNonce;
|
||||
genesis.nSolution = nSolution;
|
||||
genesis.nVersion = nVersion;
|
||||
genesis.vtx.push_back(txNew);
|
||||
genesis.hashPrevBlock.SetNull();
|
||||
genesis.hashMerkleRoot = genesis.BuildMerkleTree();
|
||||
return genesis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the genesis block. Note that the output of its generation
|
||||
* transaction cannot be spent since it did not originally exist in the
|
||||
* database (and is in any case of zero value).
|
||||
*
|
||||
* >>> from pyblake2 import blake2s
|
||||
* >>> 'Zcash' + blake2s(b'The Economist 2016-10-29 Known unknown: Another crypto-currency is born. BTC#436254 0000000000000000044f321997f336d2908cf8c8d6893e88dbf067e2d949487d ETH#2521903 483039a6b6bd8bd05f0584f9a078d075e454925eb71c1f13eaff59b405a721bb DJIA close on 27 Oct 2016: 18,169.68').hexdigest()
|
||||
*
|
||||
* CBlock(hash=00040fe8, ver=4, hashPrevBlock=00000000000000, hashMerkleRoot=c4eaa5, nTime=1477641360, nBits=1f07ffff, nNonce=4695, vtx=1)
|
||||
* CTransaction(hash=c4eaa5, ver=1, vin.size=1, vout.size=1, nLockTime=0)
|
||||
* CTxIn(COutPoint(000000, -1), coinbase 04ffff071f0104455a6361736830623963346565663862376363343137656535303031653335303039383462366665613335363833613763616331343161303433633432303634383335643334)
|
||||
* CTxOut(nValue=0.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
|
||||
* vMerkleTree: c4eaa5
|
||||
*/
|
||||
static CBlock CreateGenesisBlock(uint32_t nTime, const uint256& nNonce, const std::vector<unsigned char>& nSolution, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
||||
{
|
||||
const char* pszTimestamp = "Zcash0b9c4eef8b7cc417ee5001e3500984b6fea35683a7cac141a043c42064835d34";
|
||||
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nSolution, nBits, nVersion, genesisReward);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main network
|
||||
*/
|
||||
@@ -59,6 +105,16 @@ public:
|
||||
consensus.nPowMaxAdjustUp = 16; // 16% adjustment up
|
||||
consensus.nPowTargetSpacing = 1 * 60;
|
||||
consensus.fPowAllowMinDifficultyBlocks = true; //false;
|
||||
consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002;
|
||||
consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::ALWAYS_ACTIVE;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nProtocolVersion = 170002;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nProtocolVersion = 170004;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
|
||||
/**
|
||||
* The message start string is designed to be unlikely to occur in normal data.
|
||||
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
|
||||
@@ -77,11 +133,12 @@ public:
|
||||
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
||||
nEquihashN = N;
|
||||
nEquihashK = K;
|
||||
|
||||
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
|
||||
CMutableTransaction txNew;
|
||||
txNew.vin.resize(1);
|
||||
txNew.vout.resize(1);
|
||||
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
|
||||
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
|
||||
txNew.vout[0].nValue = 50 * COIN;
|
||||
txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
genesis.vtx.push_back(txNew);
|
||||
@@ -93,13 +150,21 @@ public:
|
||||
genesis.nNonce = uint256S("0x000000000000000000000000000000000000000000000000000000000000000b");
|
||||
genesis.nSolution = ParseHex("000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2");
|
||||
|
||||
|
||||
/*genesis = CreateGenesisBlock(
|
||||
1477641360,
|
||||
uint256S("0x0000000000000000000000000000000000000000000000000000000000001257"),
|
||||
ParseHex("000a889f00854b8665cd555f4656f68179d31ccadc1b1f7fb0952726313b16941da348284d67add4686121d4e3d930160c1348d8191c25f12b267a6a9c131b5031cbf8af1f79c9d513076a216ec87ed045fa966e01214ed83ca02dc1797270a454720d3206ac7d931a0a680c5c5e099057592570ca9bdf6058343958b31901fce1a15a4f38fd347750912e14004c73dfe588b903b6c03166582eeaf30529b14072a7b3079e3a684601b9b3024054201f7440b0ee9eb1a7120ff43f713735494aa27b1f8bab60d7f398bca14f6abb2adbf29b04099121438a7974b078a11635b594e9170f1086140b4173822dd697894483e1c6b4e8b8dcd5cb12ca4903bc61e108871d4d915a9093c18ac9b02b6716ce1013ca2c1174e319c1a570215bc9ab5f7564765f7be20524dc3fdf8aa356fd94d445e05ab165ad8bb4a0db096c097618c81098f91443c719416d39837af6de85015dca0de89462b1d8386758b2cf8a99e00953b308032ae44c35e05eb71842922eb69797f68813b59caf266cb6c213569ae3280505421a7e3a0a37fdf8e2ea354fc5422816655394a9454bac542a9298f176e211020d63dee6852c40de02267e2fc9d5e1ff2ad9309506f02a1a71a0501b16d0d36f70cdfd8de78116c0c506ee0b8ddfdeb561acadf31746b5a9dd32c21930884397fb1682164cb565cc14e089d66635a32618f7eb05fe05082b8a3fae620571660a6b89886eac53dec109d7cbb6930ca698a168f301a950be152da1be2b9e07516995e20baceebecb5579d7cdbc16d09f3a50cb3c7dffe33f26686d4ff3f8946ee6475e98cf7b3cf9062b6966e838f865ff3de5fb064a37a21da7bb8dfd2501a29e184f207caaba364f36f2329a77515dcb710e29ffbf73e2bbd773fab1f9a6b005567affff605c132e4e4dd69f36bd201005458cfbd2c658701eb2a700251cefd886b1e674ae816d3f719bac64be649c172ba27a4fd55947d95d53ba4cbc73de97b8af5ed4840b659370c556e7376457f51e5ebb66018849923db82c1c9a819f173cccdb8f3324b239609a300018d0fb094adf5bd7cbb3834c69e6d0b3798065c525b20f040e965e1a161af78ff7561cd874f5f1b75aa0bc77f720589e1b810f831eac5073e6dd46d00a2793f70f7427f0f798f2f53a67e615e65d356e66fe40609a958a05edb4c175bcc383ea0530e67ddbe479a898943c6e3074c6fcc252d6014de3a3d292b03f0d88d312fe221be7be7e3c59d07fa0f2f4029e364f1f355c5d01fa53770d0cd76d82bf7e60f6903bc1beb772e6fde4a70be51d9c7e03c8d6d8dfb361a234ba47c470fe630820bbd920715621b9fbedb49fcee165ead0875e6c2b1af16f50b5d6140cc981122fcbcf7c5a4e3772b3661b628e08380abc545957e59f634705b1bbde2f0b4e055a5ec5676d859be77e20962b645e051a880fddb0180b4555789e1f9344a436a84dc5579e2553f1e5fb0a599c137be36cabbed0319831fea3fddf94ddc7971e4bcf02cdc93294a9aab3e3b13e3b058235b4f4ec06ba4ceaa49d675b4ba80716f3bc6976b1fbf9c8bf1f3e3a4dc1cd83ef9cf816667fb94f1e923ff63fef072e6a19321e4812f96cb0ffa864da50ad74deb76917a336f31dce03ed5f0303aad5e6a83634f9fcc371096f8288b8f02ddded5ff1bb9d49331e4a84dbe1543164438fde9ad71dab024779dcdde0b6602b5ae0a6265c14b94edd83b37403f4b78fcd2ed555b596402c28ee81d87a909c4e8722b30c71ecdd861b05f61f8b1231795c76adba2fdefa451b283a5d527955b9f3de1b9828e7b2e74123dd47062ddcc09b05e7fa13cb2212a6fdbc65d7e852cec463ec6fd929f5b8483cf3052113b13dac91b69f49d1b7d1aec01c4a68e41ce157"),
|
||||
0x1f07ffff, 4, 0);*/
|
||||
|
||||
consensus.hashGenesisBlock = genesis.GetHash();
|
||||
assert(consensus.hashGenesisBlock == uint256S("0x027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71"));
|
||||
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
|
||||
vFixedSeeds.clear();
|
||||
vSeeds.clear();
|
||||
vSeeds.push_back(CDNSSeedData("komodoplatform.com", "seeds.komodoplatform.com")); // @kolo
|
||||
vSeeds.push_back(CDNSSeedData("komodo.mewhub.com", "seeds.komodo.mewhub.com")); // @kolo
|
||||
vSeeds.push_back(CDNSSeedData("komodoplatform.com", "seeds.komodoplatform.com")); // @kolo - old static dns seeds
|
||||
vSeeds.push_back(CDNSSeedData("kolo.supernet.org", "static.kolo.supernet.org")); // @kolo - new static dns seeds ToDo
|
||||
vSeeds.push_back(CDNSSeedData("kolo.supernet.org", "dynamic.kolo.supernet.org")); // @kolo - crawler seeds ToDo
|
||||
// TODO: set up bootstrapping for mainnet
|
||||
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,60);
|
||||
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,85);
|
||||
@@ -118,21 +183,6 @@ public:
|
||||
fRequireStandard = true;
|
||||
fMineBlocksOnDemand = false;
|
||||
fTestnetToBeDeprecatedFieldRPC = false;
|
||||
/*
|
||||
checkpointData = (Checkpoints::CCheckpointData)
|
||||
{
|
||||
boost::assign::map_list_of
|
||||
(0, consensus.hashGenesisBlock),
|
||||
//(2500, uint256S("0x0e6a3d5a46eba97c4e7618d66a39f115729e1176433c98481124c2bf733aa54e"))
|
||||
//(15000, uint256S("0x00f0bd236790e903321a2d22f85bd6bf8a505f6ef4eddb20458a65d37e14d142")),
|
||||
//(100000, uint256S("0x0f02eb1f3a4b89df9909fec81a4bd7d023e32e24e1f5262d9fc2cc36a715be6f")),
|
||||
1481120910, // * UNIX timestamp of last checkpoint block
|
||||
110415, // * total number of transactions between genesis and last checkpoint
|
||||
// (the tx=... number in the SetBestChain debug.log lines)
|
||||
2777 // * estimated number of transactions per day after checkpoint
|
||||
// total number of tx / (checkpoint block height / (24 * 24))
|
||||
};
|
||||
*/
|
||||
|
||||
// LogPrintf(">>>>>>>> ac_name = %u\n",GetArg("-ac_name","").c_str());
|
||||
|
||||
@@ -151,14 +201,14 @@ public:
|
||||
};
|
||||
static CMainParams mainParams;
|
||||
|
||||
void CChainParams::SetCheckpointData(Checkpoints::CCheckpointData checkpointData)
|
||||
void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointData)
|
||||
{
|
||||
CChainParams::checkpointData = checkpointData;
|
||||
}
|
||||
|
||||
void *chainparams_commandline(void *ptr)
|
||||
{
|
||||
Checkpoints::CCheckpointData checkpointData;
|
||||
CChainParams::CCheckpointData checkpointData;
|
||||
while ( ASSETCHAINS_PORT == 0 )
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -353,25 +403,49 @@ void *chainparams_commandline(void *ptr)
|
||||
/**
|
||||
* Testnet (v3)
|
||||
*/
|
||||
class CTestNetParams : public CMainParams {
|
||||
class CTestNetParams : public CChainParams {
|
||||
public:
|
||||
CTestNetParams() {
|
||||
strNetworkID = "test";
|
||||
strCurrencyUnits = "TAZ";
|
||||
consensus.fCoinbaseMustBeProtected = true;
|
||||
consensus.nSubsidySlowStartInterval = 20000;
|
||||
consensus.nSubsidyHalvingInterval = 840000;
|
||||
consensus.nMajorityEnforceBlockUpgrade = 51;
|
||||
consensus.nMajorityRejectBlockOutdated = 75;
|
||||
consensus.nMajorityWindow = 400;
|
||||
consensus.powLimit = uint256S("07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
consensus.nPowAveragingWindow = 17;
|
||||
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
|
||||
|
||||
vAlertPubKey = ParseHex("00");
|
||||
nDefaultPort = 17770;
|
||||
nMinerThreads = 0;
|
||||
consensus.nPowMaxAdjustDown = 32; // 32% adjustment down
|
||||
consensus.nPowMaxAdjustUp = 16; // 16% adjustment up
|
||||
consensus.nPowTargetSpacing = 2.5 * 60;
|
||||
consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002;
|
||||
consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::ALWAYS_ACTIVE;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nProtocolVersion = 170002;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nProtocolVersion = 170003;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = 207500;
|
||||
|
||||
consensus.fPowAllowMinDifficultyBlocks = true;
|
||||
pchMessageStart[0] = 0x5A;
|
||||
pchMessageStart[1] = 0x1F;
|
||||
pchMessageStart[2] = 0x7E;
|
||||
pchMessageStart[3] = 0x62;
|
||||
vAlertPubKey = ParseHex("00");
|
||||
nDefaultPort = 17770;
|
||||
nMinerThreads = 0;
|
||||
vAlertPubKey = ParseHex("020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9");
|
||||
nMaxTipAge = 24 * 60 * 60;
|
||||
|
||||
nPruneAfterHeight = 1000;
|
||||
const size_t N = 200, K = 9;
|
||||
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
||||
nEquihashN = N;
|
||||
nEquihashK = K;
|
||||
|
||||
//! Modify the testnet genesis block so the timestamp is valid for a later start.
|
||||
genesis.nTime = 1296688602;
|
||||
@@ -402,7 +476,7 @@ public:
|
||||
fMineBlocksOnDemand = false;
|
||||
fTestnetToBeDeprecatedFieldRPC = true;
|
||||
|
||||
checkpointData = (Checkpoints::CCheckpointData) {
|
||||
checkpointData = (CCheckpointData) {
|
||||
boost::assign::map_list_of
|
||||
(0, consensus.hashGenesisBlock)
|
||||
(38000, uint256S("0x001e9a2d2e2892b88e9998cf7b079b41d59dd085423a921fe8386cecc42287b8")),
|
||||
@@ -418,7 +492,7 @@ static CTestNetParams testNetParams;
|
||||
/**
|
||||
* Regression test
|
||||
*/
|
||||
class CRegTestParams : public CTestNetParams {
|
||||
class CRegTestParams : public CChainParams {
|
||||
public:
|
||||
CRegTestParams() {
|
||||
strNetworkID = "regtest";
|
||||
@@ -430,15 +504,28 @@ public:
|
||||
consensus.nMajorityRejectBlockOutdated = 950;
|
||||
consensus.nMajorityWindow = 1000;
|
||||
consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||
consensus.nPowAveragingWindow = 17;
|
||||
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
|
||||
consensus.nPowMaxAdjustDown = 0; // Turn off adjustment down
|
||||
consensus.nPowMaxAdjustUp = 0; // Turn off adjustment up
|
||||
consensus.nPowTargetSpacing = 2.5 * 60;
|
||||
consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002;
|
||||
consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::ALWAYS_ACTIVE;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nProtocolVersion = 170002;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nProtocolVersion = 170003;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
|
||||
pchMessageStart[0] = 0xaa;
|
||||
pchMessageStart[1] = 0x8e;
|
||||
pchMessageStart[2] = 0xf3;
|
||||
pchMessageStart[3] = 0xf5;
|
||||
nMinerThreads = 1;
|
||||
nMaxTipAge = 24 * 60 * 60;
|
||||
nPruneAfterHeight = 1000;
|
||||
const size_t N = 48, K = 5;
|
||||
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
||||
nEquihashN = N;
|
||||
@@ -449,7 +536,6 @@ public:
|
||||
genesis.nSolution = ParseHex("0f2a976db4c4263da10fd5d38eb1790469cf19bdb4bf93450e09a72fdff17a3454326399");
|
||||
consensus.hashGenesisBlock = genesis.GetHash();
|
||||
nDefaultPort = 17779;
|
||||
assert(consensus.hashGenesisBlock == uint256S("0x00a215b4fe36f5d2f829d43e587bf10e89e64f9f48a5b6ce18559089e8fd643d"));
|
||||
nPruneAfterHeight = 1000;
|
||||
|
||||
vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds.
|
||||
@@ -461,18 +547,34 @@ public:
|
||||
fMineBlocksOnDemand = true;
|
||||
fTestnetToBeDeprecatedFieldRPC = false;
|
||||
|
||||
checkpointData = (Checkpoints::CCheckpointData){
|
||||
checkpointData = (CCheckpointData){
|
||||
boost::assign::map_list_of
|
||||
( 0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")),
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
// These prefixes are the same as the testnet prefixes
|
||||
base58Prefixes[PUBKEY_ADDRESS] = {0x1D,0x25};
|
||||
base58Prefixes[SCRIPT_ADDRESS] = {0x1C,0xBA};
|
||||
base58Prefixes[SECRET_KEY] = {0xEF};
|
||||
// do not rely on these BIP32 prefixes; they are not specified and may change
|
||||
base58Prefixes[EXT_PUBLIC_KEY] = {0x04,0x35,0x87,0xCF};
|
||||
base58Prefixes[EXT_SECRET_KEY] = {0x04,0x35,0x83,0x94};
|
||||
base58Prefixes[ZCPAYMENT_ADDRRESS] = {0x16,0xB6};
|
||||
base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAC,0x0C};
|
||||
base58Prefixes[ZCSPENDING_KEY] = {0xAC,0x08};
|
||||
|
||||
// Founders reward script expects a vector of 2-of-3 multisig addresses
|
||||
vFoundersRewardAddress = { "t2FwcEhFdNXuFMv1tcYwaBJtYVtMj8b1uTg" };
|
||||
assert(vFoundersRewardAddress.size() <= consensus.GetLastFoundersRewardBlockHeight());
|
||||
}
|
||||
|
||||
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
|
||||
{
|
||||
assert(idx > Consensus::BASE_SPROUT && idx < Consensus::MAX_NETWORK_UPGRADES);
|
||||
consensus.vUpgrades[idx].nActivationHeight = nActivationHeight;
|
||||
}
|
||||
};
|
||||
static CRegTestParams regTestParams;
|
||||
|
||||
@@ -537,7 +639,7 @@ CScript CChainParams::GetFoundersRewardScriptAtHeight(int nHeight) const {
|
||||
CBitcoinAddress address(GetFoundersRewardAddressAtHeight(nHeight).c_str());
|
||||
assert(address.IsValid());
|
||||
assert(address.IsScript());
|
||||
CScriptID scriptID = get<CScriptID>(address.Get()); // Get() returns a boost variant
|
||||
CScriptID scriptID = boost::get<CScriptID>(address.Get()); // Get() returns a boost variant
|
||||
CScript script = CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
|
||||
return script;
|
||||
}
|
||||
@@ -546,3 +648,8 @@ std::string CChainParams::GetFoundersRewardAddressAtIndex(int i) const {
|
||||
assert(i >= 0 && i < vFoundersRewardAddress.size());
|
||||
return vFoundersRewardAddress[i];
|
||||
}
|
||||
|
||||
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
|
||||
{
|
||||
regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#define BITCOIN_CHAINPARAMS_H
|
||||
|
||||
#include "chainparamsbase.h"
|
||||
#include "checkpoints.h"
|
||||
#include "consensus/params.h"
|
||||
#include "primitives/block.h"
|
||||
#include "protocol.h"
|
||||
@@ -26,6 +25,8 @@ struct SeedSpec6 {
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
typedef std::map<int, uint256> MapCheckpoints;
|
||||
|
||||
|
||||
/**
|
||||
* CChainParams defines various tweakable parameters of a given instance of the
|
||||
@@ -46,17 +47,22 @@ public:
|
||||
|
||||
ZCPAYMENT_ADDRRESS,
|
||||
ZCSPENDING_KEY,
|
||||
ZCVIEWING_KEY,
|
||||
|
||||
MAX_BASE58_TYPES
|
||||
};
|
||||
struct CCheckpointData {
|
||||
MapCheckpoints mapCheckpoints;
|
||||
int64_t nTimeLastCheckpoint;
|
||||
int64_t nTransactionsLastCheckpoint;
|
||||
double fTransactionsPerDay;
|
||||
};
|
||||
|
||||
const Consensus::Params& GetConsensus() const { return consensus; }
|
||||
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
|
||||
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
|
||||
int GetDefaultPort() const { return nDefaultPort; }
|
||||
|
||||
/** Used if GenerateBitcoins is called with a negative number of threads */
|
||||
int DefaultMinerThreads() const { return nMinerThreads; }
|
||||
const CBlock& GenesisBlock() const { return genesis; }
|
||||
/** Make miner wait to have peers to avoid wasting work */
|
||||
bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
|
||||
@@ -78,7 +84,7 @@ public:
|
||||
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
|
||||
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
|
||||
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
|
||||
const Checkpoints::CCheckpointData& Checkpoints() const { return checkpointData; }
|
||||
const CCheckpointData& Checkpoints() const { return checkpointData; }
|
||||
/** Return the founder's reward address and script for a given block height */
|
||||
std::string GetFoundersRewardAddressAtHeight(int height) const;
|
||||
CScript GetFoundersRewardScriptAtHeight(int height) const;
|
||||
@@ -87,7 +93,7 @@ public:
|
||||
void SetRegTestCoinbaseMustBeProtected() { consensus.fCoinbaseMustBeProtected = true; }
|
||||
|
||||
void SetDefaultPort(uint16_t port) { nDefaultPort = port; }
|
||||
void SetCheckpointData(Checkpoints::CCheckpointData checkpointData);
|
||||
void SetCheckpointData(CCheckpointData checkpointData);
|
||||
|
||||
//void setnonce(uint32_t nonce) { memcpy(&genesis.nNonce,&nonce,sizeof(nonce)); }
|
||||
//void settimestamp(uint32_t timestamp) { genesis.nTime = timestamp; }
|
||||
@@ -118,7 +124,7 @@ protected:
|
||||
bool fRequireStandard = false;
|
||||
bool fMineBlocksOnDemand = false;
|
||||
bool fTestnetToBeDeprecatedFieldRPC = false;
|
||||
Checkpoints::CCheckpointData checkpointData;
|
||||
CCheckpointData checkpointData;
|
||||
std::vector<std::string> vFoundersRewardAddress;
|
||||
};
|
||||
|
||||
@@ -140,4 +146,9 @@ void SelectParams(CBaseChainParams::Network network);
|
||||
*/
|
||||
bool SelectParamsFromCommandLine();
|
||||
|
||||
/**
|
||||
* Allows modifying the network upgrade regtest parameters.
|
||||
*/
|
||||
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight);
|
||||
|
||||
#endif // BITCOIN_CHAINPARAMS_H
|
||||
|
||||
@@ -25,7 +25,7 @@ static CBaseMainParams mainParams;
|
||||
/**
|
||||
* Testnet (v3)
|
||||
*/
|
||||
class CBaseTestNetParams : public CBaseMainParams
|
||||
class CBaseTestNetParams : public CBaseChainParams
|
||||
{
|
||||
public:
|
||||
CBaseTestNetParams()
|
||||
@@ -39,11 +39,12 @@ static CBaseTestNetParams testNetParams;
|
||||
/*
|
||||
* Regression test
|
||||
*/
|
||||
class CBaseRegTestParams : public CBaseTestNetParams
|
||||
class CBaseRegTestParams : public CBaseChainParams
|
||||
{
|
||||
public:
|
||||
CBaseRegTestParams()
|
||||
{
|
||||
nRPCPort = 18232;
|
||||
strDataDir = "regtest";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Checkpoints {
|
||||
* fast multicore CPU, it won't be much higher than 1.
|
||||
*/
|
||||
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
|
||||
bool CheckBlock(const CCheckpointData& data, int nHeight, const uint256& hash)
|
||||
bool CheckBlock(const CChainParams::CCheckpointData& data, int nHeight, const uint256& hash)
|
||||
{
|
||||
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Checkpoints {
|
||||
}
|
||||
|
||||
//! Guess how far we are in the verification process at the given block index
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
|
||||
double GuessVerificationProgress(const CChainParams::CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
|
||||
if (pindex==NULL)
|
||||
return 0.0;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Checkpoints {
|
||||
return fWorkBefore / (fWorkBefore + fWorkAfter);
|
||||
}
|
||||
|
||||
int GetTotalBlocksEstimate(const CCheckpointData& data)
|
||||
int GetTotalBlocksEstimate(const CChainParams::CCheckpointData& data)
|
||||
{
|
||||
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Checkpoints {
|
||||
return checkpoints.rbegin()->first;
|
||||
}
|
||||
|
||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
|
||||
CBlockIndex* GetLastCheckpoint(const CChainParams::CCheckpointData& data)
|
||||
{
|
||||
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
#define BITCOIN_CHECKPOINTS_H
|
||||
|
||||
#include "uint256.h"
|
||||
#include "chainparams.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
class CBlockIndex;
|
||||
struct CCheckpointData;
|
||||
|
||||
/**
|
||||
* Block-chain checkpoints are compiled-in sanity checks.
|
||||
@@ -17,7 +19,8 @@ class CBlockIndex;
|
||||
*/
|
||||
namespace Checkpoints
|
||||
{
|
||||
typedef std::map<int, uint256> MapCheckpoints;
|
||||
|
||||
typedef std::map<int, uint256> MapCheckpoints;
|
||||
|
||||
struct CCheckpointData {
|
||||
MapCheckpoints mapCheckpoints;
|
||||
@@ -25,15 +28,16 @@ struct CCheckpointData {
|
||||
int64_t nTransactionsLastCheckpoint;
|
||||
double fTransactionsPerDay;
|
||||
};
|
||||
bool CheckBlock(const CCheckpointData& data, int nHeight, const uint256& hash);
|
||||
bool CheckBlock(const CChainParams::CCheckpointData& data, int nHeight, const uint256& hash);
|
||||
|
||||
|
||||
//! Return conservative estimate of total number of blocks, 0 if unknown
|
||||
int GetTotalBlocksEstimate(const CCheckpointData& data);
|
||||
int GetTotalBlocksEstimate(const CChainParams::CCheckpointData& data);
|
||||
|
||||
//! Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
|
||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data);
|
||||
CBlockIndex* GetLastCheckpoint(const CChainParams::CCheckpointData& data);
|
||||
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex* pindex, bool fSigchecks = true);
|
||||
double GuessVerificationProgress(const CChainParams::CCheckpointData& data, CBlockIndex* pindex, bool fSigchecks = true);
|
||||
|
||||
} //namespace Checkpoints
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ const std::string CLIENT_NAME("MagicBean");
|
||||
const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
|
||||
const std::string CLIENT_DATE(BUILD_DATE);
|
||||
|
||||
static std::string FormatVersion(int nVersion)
|
||||
std::string FormatVersion(int nVersion)
|
||||
{
|
||||
if (nVersion % 100 < 25)
|
||||
return strprintf("%d.%d.%d-beta%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)+1);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
|
||||
#define CLIENT_VERSION_MAJOR 1
|
||||
#define CLIENT_VERSION_MINOR 0
|
||||
#define CLIENT_VERSION_REVISION 8
|
||||
#define CLIENT_VERSION_REVISION 15
|
||||
#define CLIENT_VERSION_BUILD 52
|
||||
|
||||
//! Set to true for release, false for prerelease or test build
|
||||
@@ -63,6 +63,7 @@ extern const std::string CLIENT_BUILD;
|
||||
extern const std::string CLIENT_DATE;
|
||||
|
||||
|
||||
std::string FormatVersion(int nVersion);
|
||||
std::string FormatFullVersion();
|
||||
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
|
||||
|
||||
|
||||
@@ -473,8 +473,6 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const
|
||||
{
|
||||
if (tx.IsCoinBase())
|
||||
return 0.0;
|
||||
//CAmount nTotalIn = 0;
|
||||
|
||||
// Joinsplits do not reveal any information about the value or age of a note, so we
|
||||
// cannot apply the priority algorithm used for transparent utxos. Instead, we just
|
||||
// use the maximum priority whenever a transaction contains any JoinSplits.
|
||||
@@ -493,34 +491,9 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const
|
||||
if (!coins->IsAvailable(txin.prevout.n)) continue;
|
||||
if (coins->nHeight < nHeight) {
|
||||
dResult += coins->vout[txin.prevout.n].nValue * (nHeight-coins->nHeight);
|
||||
//nTotalIn += coins->vout[txin.prevout.n].nValue;
|
||||
}
|
||||
}
|
||||
|
||||
// If a transaction contains a joinsplit, we boost the priority of the transaction.
|
||||
// Joinsplits do not reveal any information about the value or age of a note, so we
|
||||
// cannot apply the priority algorithm used for transparent utxos. Instead, we pick a
|
||||
// very large number and multiply it by the transaction's fee per 1000 bytes of data.
|
||||
// One trillion, 1000000000000, is equivalent to 1 ZEC utxo * 10000 blocks (~17 days).
|
||||
/*if (tx.vjoinsplit.size() > 0) {
|
||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||
nTotalIn += tx.GetJoinSplitValueIn();
|
||||
CAmount fee = nTotalIn - tx.GetValueOut();
|
||||
CFeeRate feeRate(fee, nTxSize);
|
||||
CAmount feePerK = feeRate.GetFeePerK();
|
||||
|
||||
if (feePerK == 0) {
|
||||
feePerK = 1;
|
||||
}
|
||||
|
||||
dResult += 1000000000000 * double(feePerK);
|
||||
// We cast feePerK from int64_t to double because if feePerK is a large number, say
|
||||
// close to MAX_MONEY, the multiplication operation will result in an integer overflow.
|
||||
// The variable dResult should never overflow since a 64-bit double in C++ is typically
|
||||
// a double-precision floating-point number as specified by IEE 754, with a maximum
|
||||
// value DBL_MAX of 1.79769e+308.
|
||||
}*/
|
||||
|
||||
return tx.ComputePriority(dResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
nSize += ::GetSerializeSize(VARINT(nCode), nType, nVersion);
|
||||
// spentness bitmask
|
||||
nSize += nMaskSize;
|
||||
// txouts themself
|
||||
// txouts
|
||||
for (unsigned int i = 0; i < vout.size(); i++)
|
||||
if (!vout[i].IsNull())
|
||||
nSize += ::GetSerializeSize(CTxOutCompressor(REF(vout[i])), nType, nVersion);
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
/** The minimum allowed block version (network rule) */
|
||||
static const int32_t MIN_BLOCK_VERSION = 4;
|
||||
/** The minimum allowed transaction version (network rule) */
|
||||
static const int32_t MIN_TX_VERSION = 1;
|
||||
static const int32_t SPROUT_MIN_TX_VERSION = 1;
|
||||
/** The minimum allowed transaction version (network rule) */
|
||||
static const int32_t OVERWINTER_MIN_TX_VERSION = 3;
|
||||
/** The maximum allowed transaction version (network rule) */
|
||||
static const int32_t OVERWINTER_MAX_TX_VERSION = 3;
|
||||
/** The maximum allowed size for a serialized block, in bytes (network rule) */
|
||||
static const unsigned int MAX_BLOCK_SIZE = 2000000;
|
||||
/** The maximum allowed number of signature check operations in a block (network rule) */
|
||||
@@ -18,6 +22,8 @@ static const unsigned int MAX_BLOCK_SIGOPS = 20000;
|
||||
static const unsigned int MAX_TX_SIZE = 100000;
|
||||
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
|
||||
extern int COINBASE_MATURITY;
|
||||
/** The minimum value which is invalid for expiry height, used by CTransaction and CMutableTransaction */
|
||||
static constexpr uint32_t TX_EXPIRY_HEIGHT_THRESHOLD = 500000000;
|
||||
|
||||
/** Flags for LockTime() */
|
||||
enum {
|
||||
|
||||
@@ -9,6 +9,54 @@
|
||||
#include "uint256.h"
|
||||
|
||||
namespace Consensus {
|
||||
|
||||
/**
|
||||
* Index into Params.vUpgrades and NetworkUpgradeInfo
|
||||
*
|
||||
* Being array indices, these MUST be numbered consecutively.
|
||||
*
|
||||
* The order of these indices MUST match the order of the upgrades on-chain, as
|
||||
* several functions depend on the enum being sorted.
|
||||
*/
|
||||
enum UpgradeIndex {
|
||||
// Sprout must be first
|
||||
BASE_SPROUT,
|
||||
UPGRADE_TESTDUMMY,
|
||||
UPGRADE_OVERWINTER,
|
||||
// NOTE: Also add new upgrades to NetworkUpgradeInfo in upgrades.cpp
|
||||
MAX_NETWORK_UPGRADES
|
||||
};
|
||||
|
||||
struct NetworkUpgrade {
|
||||
/**
|
||||
* The first protocol version which will understand the new consensus rules
|
||||
*/
|
||||
int nProtocolVersion;
|
||||
|
||||
/**
|
||||
* Height of the first block for which the new consensus rules will be active
|
||||
*/
|
||||
int nActivationHeight;
|
||||
|
||||
/**
|
||||
* Special value for nActivationHeight indicating that the upgrade is always active.
|
||||
* This is useful for testing, as it means tests don't need to deal with the activation
|
||||
* process (namely, faking a chain of somewhat-arbitrary length).
|
||||
*
|
||||
* New blockchains that want to enable upgrade rules from the beginning can also use
|
||||
* this value. However, additional care must be taken to ensure the genesis block
|
||||
* satisfies the enabled rules.
|
||||
*/
|
||||
static constexpr int ALWAYS_ACTIVE = 0;
|
||||
|
||||
/**
|
||||
* Special value for nActivationHeight indicating that the upgrade will never activate.
|
||||
* This is useful when adding upgrade code that has a testnet activation height, but
|
||||
* should remain disabled on mainnet.
|
||||
*/
|
||||
static constexpr int NO_ACTIVATION_HEIGHT = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parameters that influence chain consensus.
|
||||
*/
|
||||
@@ -39,9 +87,10 @@ struct Params {
|
||||
int nMajorityEnforceBlockUpgrade;
|
||||
int nMajorityRejectBlockOutdated;
|
||||
int nMajorityWindow;
|
||||
int fPowAllowMinDifficultyBlocks;
|
||||
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES];
|
||||
/** Proof of work parameters */
|
||||
uint256 powLimit;
|
||||
bool fPowAllowMinDifficultyBlocks;
|
||||
int64_t nPowAveragingWindow;
|
||||
int64_t nPowMaxAdjustDown;
|
||||
int64_t nPowMaxAdjustUp;
|
||||
|
||||
126
src/consensus/upgrades.cpp
Normal file
126
src/consensus/upgrades.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright (c) 2018 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "consensus/upgrades.h"
|
||||
|
||||
/**
|
||||
* General information about each network upgrade.
|
||||
* Ordered by Consensus::UpgradeIndex.
|
||||
*/
|
||||
const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = {
|
||||
{
|
||||
/*.nBranchId =*/ 0,
|
||||
/*.strName =*/ "Sprout",
|
||||
/*.strInfo =*/ "The Zcash network at launch",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0x74736554,
|
||||
/*.strName =*/ "Test dummy",
|
||||
/*.strInfo =*/ "Test dummy info",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0x5ba81b19,
|
||||
/*.strName =*/ "Overwinter",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/overwinter.html for details.",
|
||||
}
|
||||
};
|
||||
|
||||
const uint32_t SPROUT_BRANCH_ID = NetworkUpgradeInfo[Consensus::BASE_SPROUT].nBranchId;
|
||||
|
||||
UpgradeState NetworkUpgradeState(
|
||||
int nHeight,
|
||||
const Consensus::Params& params,
|
||||
Consensus::UpgradeIndex idx)
|
||||
{
|
||||
assert(nHeight >= 0);
|
||||
assert(idx >= Consensus::BASE_SPROUT && idx < Consensus::MAX_NETWORK_UPGRADES);
|
||||
auto nActivationHeight = params.vUpgrades[idx].nActivationHeight;
|
||||
|
||||
if (nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) {
|
||||
return UPGRADE_DISABLED;
|
||||
} else if (nHeight >= nActivationHeight) {
|
||||
// From ZIP 200:
|
||||
//
|
||||
// ACTIVATION_HEIGHT
|
||||
// The non-zero block height at which the network upgrade rules will come
|
||||
// into effect, and be enforced as part of the blockchain consensus.
|
||||
//
|
||||
// For removal of ambiguity, the block at height ACTIVATION_HEIGHT - 1 is
|
||||
// subject to the pre-upgrade consensus rules, and would be the last common
|
||||
// block in the event of a persistent pre-upgrade branch.
|
||||
return UPGRADE_ACTIVE;
|
||||
} else {
|
||||
return UPGRADE_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkUpgradeActive(
|
||||
int nHeight,
|
||||
const Consensus::Params& params,
|
||||
Consensus::UpgradeIndex idx)
|
||||
{
|
||||
return NetworkUpgradeState(nHeight, params, idx) == UPGRADE_ACTIVE;
|
||||
}
|
||||
|
||||
int CurrentEpoch(int nHeight, const Consensus::Params& params) {
|
||||
for (auto idxInt = Consensus::MAX_NETWORK_UPGRADES - 1; idxInt >= Consensus::BASE_SPROUT; idxInt--) {
|
||||
if (NetworkUpgradeActive(nHeight, params, Consensus::UpgradeIndex(idxInt))) {
|
||||
return idxInt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) {
|
||||
return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId;
|
||||
}
|
||||
|
||||
bool IsActivationHeight(
|
||||
int nHeight,
|
||||
const Consensus::Params& params,
|
||||
Consensus::UpgradeIndex idx)
|
||||
{
|
||||
assert(idx >= Consensus::BASE_SPROUT && idx < Consensus::MAX_NETWORK_UPGRADES);
|
||||
|
||||
// Don't count Sprout as an activation height
|
||||
if (idx == Consensus::BASE_SPROUT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return nHeight >= 0 && nHeight == params.vUpgrades[idx].nActivationHeight;
|
||||
}
|
||||
|
||||
bool IsActivationHeightForAnyUpgrade(
|
||||
int nHeight,
|
||||
const Consensus::Params& params)
|
||||
{
|
||||
if (nHeight < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't count Sprout as an activation height
|
||||
for (int idx = Consensus::BASE_SPROUT + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) {
|
||||
if (nHeight == params.vUpgrades[idx].nActivationHeight)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::optional<int> NextActivationHeight(
|
||||
int nHeight,
|
||||
const Consensus::Params& params)
|
||||
{
|
||||
if (nHeight < 0) {
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
// Don't count Sprout as an activation height
|
||||
for (auto idx = Consensus::BASE_SPROUT + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) {
|
||||
if (NetworkUpgradeState(nHeight, params, Consensus::UpgradeIndex(idx)) == UPGRADE_PENDING) {
|
||||
return params.vUpgrades[idx].nActivationHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return boost::none;
|
||||
}
|
||||
90
src/consensus/upgrades.h
Normal file
90
src/consensus/upgrades.h
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright (c) 2018 The Zcash developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef ZCASH_CONSENSUS_UPGRADES_H
|
||||
#define ZCASH_CONSENSUS_UPGRADES_H
|
||||
|
||||
#include "consensus/params.h"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
enum UpgradeState {
|
||||
UPGRADE_DISABLED,
|
||||
UPGRADE_PENDING,
|
||||
UPGRADE_ACTIVE
|
||||
};
|
||||
|
||||
struct NUInfo {
|
||||
/** Branch ID (a random non-zero 32-bit value) */
|
||||
uint32_t nBranchId;
|
||||
/** User-facing name for the upgrade */
|
||||
std::string strName;
|
||||
/** User-facing information string about the upgrade */
|
||||
std::string strInfo;
|
||||
};
|
||||
|
||||
extern const struct NUInfo NetworkUpgradeInfo[];
|
||||
|
||||
// Consensus branch id to identify pre-overwinter (Sprout) consensus rules.
|
||||
extern const uint32_t SPROUT_BRANCH_ID;
|
||||
|
||||
/**
|
||||
* Checks the state of a given network upgrade based on block height.
|
||||
* Caller must check that the height is >= 0 (and handle unknown heights).
|
||||
*/
|
||||
UpgradeState NetworkUpgradeState(
|
||||
int nHeight,
|
||||
const Consensus::Params& params,
|
||||
Consensus::UpgradeIndex idx);
|
||||
|
||||
/**
|
||||
* Returns true if the given network upgrade is active as of the given block
|
||||
* height. Caller must check that the height is >= 0 (and handle unknown
|
||||
* heights).
|
||||
*/
|
||||
bool NetworkUpgradeActive(
|
||||
int nHeight,
|
||||
const Consensus::Params& params,
|
||||
Consensus::UpgradeIndex idx);
|
||||
|
||||
/**
|
||||
* Returns the index of the most recent upgrade as of the given block height
|
||||
* (corresponding to the current "epoch"). Consensus::BASE_SPROUT is the
|
||||
* default value if no upgrades are active. Caller must check that the height
|
||||
* is >= 0 (and handle unknown heights).
|
||||
*/
|
||||
int CurrentEpoch(int nHeight, const Consensus::Params& params);
|
||||
|
||||
/**
|
||||
* Returns the branch ID of the most recent upgrade as of the given block height
|
||||
* (corresponding to the current "epoch"), or 0 if no upgrades are active.
|
||||
* Caller must check that the height is >= 0 (and handle unknown heights).
|
||||
*/
|
||||
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params);
|
||||
|
||||
/**
|
||||
* Returns true if the given block height is the activation height for the given
|
||||
* upgrade.
|
||||
*/
|
||||
bool IsActivationHeight(
|
||||
int nHeight,
|
||||
const Consensus::Params& params,
|
||||
Consensus::UpgradeIndex upgrade);
|
||||
|
||||
/**
|
||||
* Returns true if the given block height is the activation height for any upgrade.
|
||||
*/
|
||||
bool IsActivationHeightForAnyUpgrade(
|
||||
int nHeight,
|
||||
const Consensus::Params& params);
|
||||
|
||||
/**
|
||||
* Returns the activation height for the next upgrade after the given block height,
|
||||
* or boost::none if there are no more known upgrades.
|
||||
*/
|
||||
boost::optional<int> NextActivationHeight(
|
||||
int nHeight,
|
||||
const Consensus::Params& params);
|
||||
|
||||
#endif // ZCASH_CONSENSUS_UPGRADES_H
|
||||
@@ -17,6 +17,7 @@ static const unsigned char REJECT_NONSTANDARD = 0x40;
|
||||
static const unsigned char REJECT_DUST = 0x41;
|
||||
static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
|
||||
static const unsigned char REJECT_CHECKPOINT = 0x43;
|
||||
static const unsigned char REJECT_HAVEBETTER = 0x44;
|
||||
|
||||
/** Capture information about block/transaction validation */
|
||||
class CValidationState {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "compat/endian.h"
|
||||
|
||||
#if defined(NDEBUG)
|
||||
# error "Bitcoin cannot be compiled without assertions."
|
||||
# error "Zcash cannot be compiled without assertions."
|
||||
#endif
|
||||
|
||||
uint16_t static inline ReadLE16(const unsigned char* ptr)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "config/bitcoin-config.h"
|
||||
#endif
|
||||
|
||||
#include "compat/endian.h"
|
||||
#include "crypto/equihash.h"
|
||||
#include "util.h"
|
||||
#ifndef __linux__
|
||||
|
||||
24
src/cryptoconditions/.gitignore
vendored
Normal file
24
src/cryptoconditions/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
*.pyc
|
||||
.cache
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
/aclocal.m4
|
||||
/autom4te.cache/
|
||||
/src/cryptoconditions-config.h
|
||||
/configure
|
||||
/depcomp
|
||||
/install-sh
|
||||
/libtool
|
||||
/ltmain.sh
|
||||
/m4/
|
||||
/missing
|
||||
/stamp-h?
|
||||
.deps/
|
||||
.dirstamp
|
||||
.libs/
|
||||
*.l[ao]
|
||||
*.[ao]
|
||||
*~
|
||||
converter-sample.c
|
||||
config.*
|
||||
.pytest_cache
|
||||
10
src/cryptoconditions/.travis.yml
Normal file
10
src/cryptoconditions/.travis.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
language: C
|
||||
sudo: true
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
before_script: ./autogen.sh
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gdb
|
||||
13
src/cryptoconditions/LICENSE
Normal file
13
src/cryptoconditions/LICENSE
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright 2017 Scott Sadler
|
||||
|
||||
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.
|
||||
91
src/cryptoconditions/Makefile.am
Normal file
91
src/cryptoconditions/Makefile.am
Normal file
@@ -0,0 +1,91 @@
|
||||
lib_LTLIBRARIES=libcryptoconditions.la
|
||||
noinst_LTLIBRARIES=$(CRYPTOCONDITIONS_CORE)
|
||||
SUBDIRS = src/include/secp256k1
|
||||
|
||||
include_HEADERS = include/cryptoconditions.h
|
||||
|
||||
# Have a separate build target for cryptoconditions that does not contain secp256k1
|
||||
|
||||
libcryptoconditions_la_SOURCES = include/cryptoconditions.h
|
||||
libcryptoconditions_la_LIBADD = $(CRYPTOCONDITIONS_CORE) $(LIBSECP256K1)
|
||||
|
||||
AM_CFLAGS = -I$(top_srcdir)/src/asn -I$(top_srcdir)/include -I$(top_srcdir)/src/include \
|
||||
-Wall -Wno-pointer-sign -Wno-discarded-qualifiers
|
||||
|
||||
LIBSECP256K1=src/include/secp256k1/libsecp256k1.la
|
||||
|
||||
$(LIBSECP256K1): $(wildcard src/secp256k1/*)
|
||||
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
|
||||
|
||||
CRYPTOCONDITIONS_CORE=libcryptoconditions_core.la
|
||||
|
||||
libcryptoconditions_core_la_SOURCES = \
|
||||
src/cryptoconditions.c \
|
||||
src/utils.c \
|
||||
src/include/cJSON.c \
|
||||
src/include/sha256.c \
|
||||
src/include/ed25519/src/keypair.c \
|
||||
src/include/ed25519/src/seed.c \
|
||||
src/include/ed25519/src/verify.c \
|
||||
src/include/ed25519/src/sign.c \
|
||||
src/include/ed25519/src/fe.c \
|
||||
src/include/ed25519/src/sc.c \
|
||||
src/include/ed25519/src/sha512.c \
|
||||
src/include/ed25519/src/ge.c \
|
||||
src/include/ed25519/src/add_scalar.c \
|
||||
src/include/ed25519/src/key_exchange.c \
|
||||
src/asn/Condition.c \
|
||||
src/asn/SimpleSha256Condition.c \
|
||||
src/asn/CompoundSha256Condition.c \
|
||||
src/asn/ConditionTypes.c \
|
||||
src/asn/Fulfillment.c \
|
||||
src/asn/PreimageFulfillment.c \
|
||||
src/asn/PrefixFulfillment.c \
|
||||
src/asn/ThresholdFulfillment.c \
|
||||
src/asn/RsaSha256Fulfillment.c \
|
||||
src/asn/Ed25519Sha512Fulfillment.c \
|
||||
src/asn/PrefixFingerprintContents.c \
|
||||
src/asn/ThresholdFingerprintContents.c \
|
||||
src/asn/RsaFingerprintContents.c \
|
||||
src/asn/Ed25519FingerprintContents.c \
|
||||
src/asn/EvalFulfillment.c \
|
||||
src/asn/Secp256k1FingerprintContents.c \
|
||||
src/asn/Secp256k1Fulfillment.c \
|
||||
src/asn/INTEGER.c \
|
||||
src/asn/NativeEnumerated.c \
|
||||
src/asn/NativeInteger.c \
|
||||
src/asn/asn_SET_OF.c \
|
||||
src/asn/constr_CHOICE.c \
|
||||
src/asn/constr_SEQUENCE.c \
|
||||
src/asn/constr_SET_OF.c \
|
||||
src/asn/OCTET_STRING.c \
|
||||
src/asn/BIT_STRING.c \
|
||||
src/asn/asn_codecs_prim.c \
|
||||
src/asn/ber_tlv_length.c \
|
||||
src/asn/ber_tlv_tag.c \
|
||||
src/asn/ber_decoder.c \
|
||||
src/asn/der_encoder.c \
|
||||
src/asn/constr_TYPE.c \
|
||||
src/asn/constraints.c \
|
||||
src/asn/xer_support.c \
|
||||
src/asn/xer_decoder.c \
|
||||
src/asn/xer_encoder.c \
|
||||
src/asn/per_support.c \
|
||||
src/asn/per_decoder.c \
|
||||
src/asn/per_encoder.c \
|
||||
src/asn/per_opentype.c
|
||||
|
||||
test:
|
||||
bash -c '[ -d .env ] || virtualenv .env -p python3'
|
||||
.env/bin/pip install pytest
|
||||
gdb -batch -ex run -ex bt --args .env/bin/python -m pytest -s -x -v 2>&1 | grep -v ^"No stack."$
|
||||
|
||||
test-debug-interactive:
|
||||
gdb -ex run --args python3 -m pytest -s -x -v
|
||||
|
||||
asn:
|
||||
cd src/asn; \
|
||||
mv asn_system.h asn_system.bak; \
|
||||
rm *.c *.h; \
|
||||
asn1c CryptoConditions.asn; \
|
||||
mv asn_system.bak asn_system.h
|
||||
165
src/cryptoconditions/README.md
Normal file
165
src/cryptoconditions/README.md
Normal file
@@ -0,0 +1,165 @@
|
||||
# libcryptoconditions [](https://travis-ci.org/libscott/libcryptoconditions)
|
||||
|
||||
Interledger Crypto-Conditions in C, targeting spec [draft-thomas-crypto-conditions-03](https://tools.ietf.org/html/draft-thomas-crypto-conditions-03).
|
||||
|
||||
Features shared object and easy to use JSON api, as well as a command line interface written in Python.
|
||||
|
||||
## Quickstart
|
||||
|
||||
```shell
|
||||
git clone --recursive https://github.com/libscott/libcryptoconditions
|
||||
cd libcryptoconditions
|
||||
./autogen.sh
|
||||
./configure
|
||||
make
|
||||
./cryptoconditions.py --help
|
||||
```
|
||||
|
||||
## Status
|
||||
|
||||
JSON interface may not be particularly safe. The rest is pretty good now.
|
||||
|
||||
## Embedding
|
||||
|
||||
For the binary interface, see [cryptoconditions.h](./include/cryptoconditions.h).
|
||||
|
||||
To embed in other languages, the easiest way may be to call the JSON RPC method via FFI. This is how it looks in Python:
|
||||
|
||||
```python
|
||||
import json
|
||||
from ctypes import *
|
||||
|
||||
so = cdll.LoadLibrary('.libs/libcryptoconditions.so')
|
||||
so.jsonRPC.restype = c_char_p
|
||||
|
||||
def call_cryptoconditions_rpc(method, params):
|
||||
out = so.jsonRPC(json.dumps({
|
||||
'method': method,
|
||||
'params': params,
|
||||
}))
|
||||
return json.loads(out)
|
||||
```
|
||||
|
||||
## JSON methods
|
||||
|
||||
### encodeCondition
|
||||
|
||||
Encode a JSON condition to a base64 binary string
|
||||
|
||||
```shell
|
||||
cryptoconditions encodeCondition '{
|
||||
"type": "ed25519-sha-256",
|
||||
"publicKey": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo"
|
||||
}'
|
||||
{
|
||||
"bin": "pCeAIHmSOauo_E_36r-8TETmnovf7ZkzJOEu1keSq-KJzx1fgQMCAAA",
|
||||
"uri": "ni:///sha-256;eZI5q6j8T_fqv7xMROaei9_tmTMk4S7WR5Kr4onPHV8?fpt=ed25519-sha-256&cost=131072"
|
||||
}
|
||||
```
|
||||
|
||||
### decodeCondition
|
||||
|
||||
Decode a binary condition
|
||||
|
||||
```shell
|
||||
cryptoconditions decodeCondition '{
|
||||
"bin": "pCeAIHmSOauo_E_36r-8TETmnovf7ZkzJOEu1keSq-KJzx1fgQMCAAA"
|
||||
}'
|
||||
{
|
||||
"bin": "pCeAIHmSOauo_E_36r-8TETmnovf7ZkzJOEu1keSq-KJzx1fgQMCAAA",
|
||||
"uri": "ni:///sha-256;eZI5q6j8T_fqv7xMROaei9_tmTMk4S7WR5Kr4onPHV8?fpt=ed25519-sha-256&cost=131072"
|
||||
}
|
||||
```
|
||||
|
||||
### encodeFulfillment
|
||||
|
||||
Encode a JSON condition to a binary fulfillment. The condition must be fulfilled, that is,
|
||||
it needs to have signatures present.
|
||||
|
||||
```shell
|
||||
cryptoconditions encodeFulfillment '{
|
||||
{
|
||||
"type": "ed25519-sha-256",
|
||||
"publicKey": "E0x0Ws4GhWhO_zBoUyaLbuqCz6hDdq11Ft1Dgbe9y9k",
|
||||
"signature": "jcuovSRpHwqiC781KzSM1Jd0Qtyfge0cMGttUdLOVdjJlSBFLTtgpinASOaJpd-VGjhSGWkp1hPWuMAAZq6pAg"
|
||||
}'
|
||||
{
|
||||
"fulfillment": "pGSAIBNMdFrOBoVoTv8waFMmi27qgs-oQ3atdRbdQ4G3vcvZgUCNy6i9JGkfCqILvzUrNIzUl3RC3J-B7Rwwa21R0s5V2MmVIEUtO2CmKcBI5oml35UaOFIZaSnWE9a4wABmrqkC"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### decodeFulfillment
|
||||
|
||||
Decode a binary fulfillment
|
||||
|
||||
```shell
|
||||
cryptoconditions decodeFulfillment '{
|
||||
"fulfillment": "pGSAINdamAGCsQq31Uv-08lkBzoO4XLz2qYjJa8CGmj3B1EagUDlVkMAw2CscpCG4syAboKKhId_Hrjl2XTYc-BlIkkBVV-4ghWQozusxh45cBz5tGvSW_XwWVu-JGVRQUOOehAL"
|
||||
}'
|
||||
{
|
||||
"bin": "pCeAIHmSOauo_E_36r-8TETmnovf7ZkzJOEu1keSq-KJzx1fgQMCAAA",
|
||||
"uri": "ni:///sha-256;eZI5q6j8T_fqv7xMROaei9_tmTMk4S7WR5Kr4onPHV8?fpt=ed25519-sha-256&cost=131072"
|
||||
}
|
||||
```
|
||||
|
||||
### verifyFulfillment
|
||||
|
||||
Verify a fulfillment against a message and a condition URL
|
||||
|
||||
```shell
|
||||
cryptoconditions verifyFulfillment '{
|
||||
"message": "",
|
||||
"fulfillment": "pGSAINdamAGCsQq31Uv-08lkBzoO4XLz2qYjJa8CGmj3B1EagUDlVkMAw2CscpCG4syAboKKhId_Hrjl2XTYc-BlIkkBVV-4ghWQozusxh45cBz5tGvSW_XwWVu-JGVRQUOOehAL",
|
||||
"condition": "pCeAIHmSOauo_E_36r-8TETmnovf7ZkzJOEu1keSq-KJzx1fgQMCAAA"
|
||||
}
|
||||
{
|
||||
"valid": true
|
||||
}
|
||||
```
|
||||
|
||||
### signTreeEd25519
|
||||
|
||||
Sign all ed25519 nodes in a condition tree
|
||||
|
||||
```shell
|
||||
cryptoconditions signTreeEd25519 '{
|
||||
"condition": {
|
||||
"type": "ed25519-sha-256",
|
||||
"publicKey": "E0x0Ws4GhWhO_zBoUyaLbuqCz6hDdq11Ft1Dgbe9y9k",
|
||||
},
|
||||
"privateKey": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo",
|
||||
"message": "",
|
||||
}'
|
||||
{
|
||||
"num_signed": 1,
|
||||
"condition": {
|
||||
"type": "ed25519-sha-256",
|
||||
"publicKey": "E0x0Ws4GhWhO_zBoUyaLbuqCz6hDdq11Ft1Dgbe9y9k",
|
||||
"signature": "jcuovSRpHwqiC781KzSM1Jd0Qtyfge0cMGttUdLOVdjJlSBFLTtgpinASOaJpd-VGjhSGWkp1hPWuMAAZq6pAg"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### signTreeSecp256k1
|
||||
|
||||
Sign all secp256k1 nodes in a condition tree
|
||||
|
||||
```shell
|
||||
cryptoconditions signTreeSecp256k1 '{
|
||||
"condition": {
|
||||
"type": "secp256k1-sha-256",
|
||||
"publicKey": "AmkauD4tVL5-I7NN9hE_A8SlA0WdCIeJe_1Nac_km1hr",
|
||||
},
|
||||
"privateKey": "Bxwd5hOLZcTvzrR5Cupm3IV7TWHHl8nNLeO4UhYfRs4",
|
||||
"message": "",
|
||||
}'
|
||||
{
|
||||
"num_signed": 1,
|
||||
"condition": {
|
||||
"type": "secp256k1-sha-256",
|
||||
"publicKey": "AmkauD4tVL5-I7NN9hE_A8SlA0WdCIeJe_1Nac_km1hr",
|
||||
"signature": "LSQLzZo4cmt04KoCdoFcbIJX5MZ9CM6324SqkdqV1PppfUwquiWa7HD97hf4jdkdqU3ep8ZS9AU7zEJoUAl_Gg"
|
||||
}
|
||||
}
|
||||
```
|
||||
3
src/cryptoconditions/autogen.sh
Executable file
3
src/cryptoconditions/autogen.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
autoreconf -if --warnings=all
|
||||
347
src/cryptoconditions/compile
Executable file
347
src/cryptoconditions/compile
Executable file
@@ -0,0 +1,347 @@
|
||||
#! /bin/sh
|
||||
# Wrapper for compilers which do not understand '-c -o'.
|
||||
|
||||
scriptversion=2012-10-14.11; # UTC
|
||||
|
||||
# Copyright (C) 1999-2014 Free Software Foundation, Inc.
|
||||
# Written by Tom Tromey <tromey@cygnus.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <bug-automake@gnu.org> or send patches to
|
||||
# <automake-patches@gnu.org>.
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
# We need space, tab and new line, in precisely that order. Quoting is
|
||||
# there to prevent tools from complaining about whitespace usage.
|
||||
IFS=" "" $nl"
|
||||
|
||||
file_conv=
|
||||
|
||||
# func_file_conv build_file lazy
|
||||
# Convert a $build file to $host form and store it in $file
|
||||
# Currently only supports Windows hosts. If the determined conversion
|
||||
# type is listed in (the comma separated) LAZY, no conversion will
|
||||
# take place.
|
||||
func_file_conv ()
|
||||
{
|
||||
file=$1
|
||||
case $file in
|
||||
/ | /[!/]*) # absolute file, and not a UNC file
|
||||
if test -z "$file_conv"; then
|
||||
# lazily determine how to convert abs files
|
||||
case `uname -s` in
|
||||
MINGW*)
|
||||
file_conv=mingw
|
||||
;;
|
||||
CYGWIN*)
|
||||
file_conv=cygwin
|
||||
;;
|
||||
*)
|
||||
file_conv=wine
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
case $file_conv/,$2, in
|
||||
*,$file_conv,*)
|
||||
;;
|
||||
mingw/*)
|
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||
;;
|
||||
cygwin/*)
|
||||
file=`cygpath -m "$file" || echo "$file"`
|
||||
;;
|
||||
wine/*)
|
||||
file=`winepath -w "$file" || echo "$file"`
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# func_cl_dashL linkdir
|
||||
# Make cl look for libraries in LINKDIR
|
||||
func_cl_dashL ()
|
||||
{
|
||||
func_file_conv "$1"
|
||||
if test -z "$lib_path"; then
|
||||
lib_path=$file
|
||||
else
|
||||
lib_path="$lib_path;$file"
|
||||
fi
|
||||
linker_opts="$linker_opts -LIBPATH:$file"
|
||||
}
|
||||
|
||||
# func_cl_dashl library
|
||||
# Do a library search-path lookup for cl
|
||||
func_cl_dashl ()
|
||||
{
|
||||
lib=$1
|
||||
found=no
|
||||
save_IFS=$IFS
|
||||
IFS=';'
|
||||
for dir in $lib_path $LIB
|
||||
do
|
||||
IFS=$save_IFS
|
||||
if $shared && test -f "$dir/$lib.dll.lib"; then
|
||||
found=yes
|
||||
lib=$dir/$lib.dll.lib
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/$lib.lib"; then
|
||||
found=yes
|
||||
lib=$dir/$lib.lib
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/lib$lib.a"; then
|
||||
found=yes
|
||||
lib=$dir/lib$lib.a
|
||||
break
|
||||
fi
|
||||
done
|
||||
IFS=$save_IFS
|
||||
|
||||
if test "$found" != yes; then
|
||||
lib=$lib.lib
|
||||
fi
|
||||
}
|
||||
|
||||
# func_cl_wrapper cl arg...
|
||||
# Adjust compile command to suit cl
|
||||
func_cl_wrapper ()
|
||||
{
|
||||
# Assume a capable shell
|
||||
lib_path=
|
||||
shared=:
|
||||
linker_opts=
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.[oO][bB][jJ])
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fo"$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fe"$file"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
-I)
|
||||
eat=1
|
||||
func_file_conv "$2" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-I*)
|
||||
func_file_conv "${1#-I}" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-l)
|
||||
eat=1
|
||||
func_cl_dashl "$2"
|
||||
set x "$@" "$lib"
|
||||
shift
|
||||
;;
|
||||
-l*)
|
||||
func_cl_dashl "${1#-l}"
|
||||
set x "$@" "$lib"
|
||||
shift
|
||||
;;
|
||||
-L)
|
||||
eat=1
|
||||
func_cl_dashL "$2"
|
||||
;;
|
||||
-L*)
|
||||
func_cl_dashL "${1#-L}"
|
||||
;;
|
||||
-static)
|
||||
shared=false
|
||||
;;
|
||||
-Wl,*)
|
||||
arg=${1#-Wl,}
|
||||
save_ifs="$IFS"; IFS=','
|
||||
for flag in $arg; do
|
||||
IFS="$save_ifs"
|
||||
linker_opts="$linker_opts $flag"
|
||||
done
|
||||
IFS="$save_ifs"
|
||||
;;
|
||||
-Xlinker)
|
||||
eat=1
|
||||
linker_opts="$linker_opts $2"
|
||||
;;
|
||||
-*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
|
||||
func_file_conv "$1"
|
||||
set x "$@" -Tp"$file"
|
||||
shift
|
||||
;;
|
||||
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
|
||||
func_file_conv "$1" mingw
|
||||
set x "$@" "$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
if test -n "$linker_opts"; then
|
||||
linker_opts="-link$linker_opts"
|
||||
fi
|
||||
exec "$@" $linker_opts
|
||||
exit 1
|
||||
}
|
||||
|
||||
eat=
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: compile [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Wrapper for compilers which do not understand '-c -o'.
|
||||
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
|
||||
arguments, and rename the output as expected.
|
||||
|
||||
If you are trying to build a whole package this is not the
|
||||
right script to run: please start by reading the file 'INSTALL'.
|
||||
|
||||
Report bugs to <bug-automake@gnu.org>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "compile $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
|
||||
func_cl_wrapper "$@" # Doesn't return...
|
||||
;;
|
||||
esac
|
||||
|
||||
ofile=
|
||||
cfile=
|
||||
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
# So we strip '-o arg' only if arg is an object.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.obj)
|
||||
ofile=$2
|
||||
;;
|
||||
*)
|
||||
set x "$@" -o "$2"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.c)
|
||||
cfile=$1
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if test -z "$ofile" || test -z "$cfile"; then
|
||||
# If no '-o' option was seen then we might have been invoked from a
|
||||
# pattern rule where we don't need one. That is ok -- this is a
|
||||
# normal compilation that the losing compiler can handle. If no
|
||||
# '.c' file was seen then we are probably linking. That is also
|
||||
# ok.
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Name of file we expect compiler to create.
|
||||
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
|
||||
|
||||
# Create the lock directory.
|
||||
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
|
||||
# that we are using for the .o file. Also, base the name on the expected
|
||||
# object file name, since that is what matters with a parallel build.
|
||||
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
|
||||
while true; do
|
||||
if mkdir "$lockdir" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
# FIXME: race condition here if user kills between mkdir and trap.
|
||||
trap "rmdir '$lockdir'; exit 1" 1 2 15
|
||||
|
||||
# Run the compile.
|
||||
"$@"
|
||||
ret=$?
|
||||
|
||||
if test -f "$cofile"; then
|
||||
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
|
||||
elif test -f "${cofile}bj"; then
|
||||
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
|
||||
fi
|
||||
|
||||
rmdir "$lockdir"
|
||||
exit $ret
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
42
src/cryptoconditions/configure.ac
Normal file
42
src/cryptoconditions/configure.ac
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
|
||||
AC_CONFIG_HEADERS([src/cryptoconditions-config.h])
|
||||
AC_CONFIG_MACRO_DIRS([m4])
|
||||
AC_CONFIG_SUBDIRS([src/include/secp256k1])
|
||||
|
||||
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
||||
LT_INIT
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_CC_STDC
|
||||
|
||||
# Checks for libraries.
|
||||
|
||||
# Checks for header files.
|
||||
AC_FUNC_ALLOCA
|
||||
AC_CHECK_HEADERS([arpa/inet.h float.h inttypes.h limits.h locale.h malloc.h netinet/in.h stddef.h stdint.h stdlib.h string.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_CHECK_HEADER_STDBOOL
|
||||
AC_TYPE_INT16_T
|
||||
AC_TYPE_INT32_T
|
||||
AC_TYPE_INT8_T
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_SSIZE_T
|
||||
AC_TYPE_UINT16_T
|
||||
AC_TYPE_UINT32_T
|
||||
AC_TYPE_UINT64_T
|
||||
AC_TYPE_UINT8_T
|
||||
AC_CHECK_TYPES([ptrdiff_t])
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_STRTOD
|
||||
AC_CHECK_FUNCS([localeconv memchr memset])
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
62
src/cryptoconditions/cryptoconditions.py
Executable file
62
src/cryptoconditions/cryptoconditions.py
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import json
|
||||
import ctypes
|
||||
import base64
|
||||
import os.path
|
||||
import argparse
|
||||
from ctypes import *
|
||||
|
||||
|
||||
so = cdll.LoadLibrary('.libs/libcryptoconditions.so')
|
||||
so.jsonRPC.restype = c_char_p
|
||||
|
||||
|
||||
def jsonRPC(method, params, load=True):
|
||||
out = so.cc_jsonRPC(json.dumps({
|
||||
'method': method,
|
||||
'params': params,
|
||||
}))
|
||||
return json.loads(out) if load else out
|
||||
|
||||
|
||||
def b16_to_b64(b16):
|
||||
return base64.urlsafe_b64encode(base64.b16decode(b16)).rstrip('=')
|
||||
|
||||
|
||||
USAGE = "cryptoconditions [-h] {method} {request_json}"
|
||||
|
||||
def get_help():
|
||||
methods = jsonRPC("listMethods", {})['methods']
|
||||
|
||||
txt = USAGE + "\n\nmethods:\n"
|
||||
|
||||
for method in methods:
|
||||
txt += ' %s: %s\n' % (method['name'], method['description'])
|
||||
|
||||
txt += """\noptional arguments:
|
||||
-h, --help show this help message and exit
|
||||
"""
|
||||
return txt
|
||||
|
||||
|
||||
def get_parser():
|
||||
class Parser(argparse.ArgumentParser):
|
||||
def format_help(self):
|
||||
return get_help()
|
||||
|
||||
parser = Parser(description='Crypto Conditions JSON interface', usage=USAGE)
|
||||
|
||||
json_loads = lambda r: json.loads(r)
|
||||
json_loads.__name__ = 'json'
|
||||
|
||||
parser.add_argument("method")
|
||||
parser.add_argument("request", type=json_loads)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = get_parser().parse_args()
|
||||
print(jsonRPC(args.method, args.request, load=False))
|
||||
106
src/cryptoconditions/include/cryptoconditions.h
Normal file
106
src/cryptoconditions/include/cryptoconditions.h
Normal file
@@ -0,0 +1,106 @@
|
||||
#include <cJSON.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#ifndef CRYPTOCONDITIONS_H
|
||||
#define CRYPTOCONDITIONS_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct CC;
|
||||
struct CCType;
|
||||
|
||||
|
||||
enum CCTypeId {
|
||||
CC_Anon = -1,
|
||||
CC_Preimage = 0,
|
||||
CC_Prefix = 1,
|
||||
CC_Threshold = 2,
|
||||
CC_Ed25519 = 4,
|
||||
CC_Secp256k1 = 5,
|
||||
CC_Eval = 15
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Evaliliary verification callback
|
||||
*/
|
||||
typedef int (*VerifyEval)(struct CC *cond, void *context);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Crypto Condition
|
||||
*/
|
||||
typedef struct CC {
|
||||
struct CCType *type;
|
||||
union {
|
||||
// public key types
|
||||
struct { uint8_t *publicKey, *signature; };
|
||||
// preimage
|
||||
struct { uint8_t *preimage; size_t preimageLength; };
|
||||
// threshold
|
||||
struct { long threshold; uint8_t size; struct CC **subconditions; };
|
||||
// prefix
|
||||
struct { uint8_t *prefix; size_t prefixLength; struct CC *subcondition;
|
||||
size_t maxMessageLength; };
|
||||
// eval
|
||||
struct { uint8_t *code; size_t codeLength; };
|
||||
// anon
|
||||
struct { uint8_t fingerprint[32]; uint32_t subtypes; unsigned long cost;
|
||||
struct CCType *conditionType; };
|
||||
};
|
||||
} CC;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Crypto Condition Visitor
|
||||
*/
|
||||
typedef struct CCVisitor {
|
||||
int (*visit)(CC *cond, struct CCVisitor visitor);
|
||||
const uint8_t *msg;
|
||||
size_t msgLength;
|
||||
void *context;
|
||||
} CCVisitor;
|
||||
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
int cc_isFulfilled(const CC *cond);
|
||||
int cc_verify(const struct CC *cond, const uint8_t *msg, size_t msgLength,
|
||||
int doHashMessage, const uint8_t *condBin, size_t condBinLength,
|
||||
VerifyEval verifyEval, void *evalContext);
|
||||
int cc_visit(CC *cond, struct CCVisitor visitor);
|
||||
int cc_signTreeEd25519(CC *cond, const uint8_t *privateKey, const uint8_t *msg,
|
||||
const size_t msgLength);
|
||||
int cc_signTreeSecp256k1Msg32(CC *cond, const uint8_t *privateKey, const uint8_t *msg32);
|
||||
int cc_secp256k1VerifyTreeMsg32(const CC *cond, const uint8_t *msg32);
|
||||
size_t cc_conditionBinary(const CC *cond, uint8_t *buf);
|
||||
size_t cc_fulfillmentBinary(const CC *cond, uint8_t *buf, size_t bufLength);
|
||||
struct CC* cc_conditionFromJSON(cJSON *params, char *err);
|
||||
struct CC* cc_conditionFromJSONString(const char *json, char *err);
|
||||
struct CC* cc_readConditionBinary(const uint8_t *cond_bin, size_t cond_bin_len);
|
||||
struct CC* cc_readFulfillmentBinary(const uint8_t *ffill_bin, size_t ffill_bin_len);
|
||||
struct CC* cc_new(int typeId);
|
||||
struct cJSON* cc_conditionToJSON(const CC *cond);
|
||||
char* cc_conditionToJSONString(const CC *cond);
|
||||
char* cc_conditionUri(const CC *cond);
|
||||
char* cc_jsonRPC(char *request);
|
||||
char* cc_typeName(const CC *cond);
|
||||
enum CCTypeId cc_typeId(const CC *cond);
|
||||
unsigned long cc_getCost(const CC *cond);
|
||||
uint32_t cc_typeMask(const CC *cond);
|
||||
int cc_isAnon(const CC *cond);
|
||||
void cc_free(struct CC *cond);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTOCONDITIONS_H */
|
||||
73
src/cryptoconditions/src/anon.c
Normal file
73
src/cryptoconditions/src/anon.c
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
#include "asn/Condition.h"
|
||||
#include "asn/Fulfillment.h"
|
||||
#include "asn/PrefixFingerprintContents.h"
|
||||
#include "asn/OCTET_STRING.h"
|
||||
#include "include/cJSON.h"
|
||||
#include "cryptoconditions.h"
|
||||
|
||||
|
||||
struct CCType CC_AnonType;
|
||||
|
||||
|
||||
CC *mkAnon(const Condition_t *asnCond) {
|
||||
|
||||
CCType *realType = getTypeByAsnEnum(asnCond->present);
|
||||
if (!realType) {
|
||||
fprintf(stderr, "Unknown ASN type: %i", asnCond->present);
|
||||
return 0;
|
||||
}
|
||||
CC *cond = cc_new(CC_Anon);
|
||||
cond->conditionType = realType;
|
||||
const CompoundSha256Condition_t *deets = &asnCond->choice.thresholdSha256;
|
||||
memcpy(cond->fingerprint, deets->fingerprint.buf, 32);
|
||||
cond->cost = deets->cost;
|
||||
if (realType->getSubtypes) {
|
||||
cond->subtypes = fromAsnSubtypes(deets->subtypes);
|
||||
}
|
||||
return cond;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void anonToJSON(const CC *cond, cJSON *params) {
|
||||
unsigned char *b64 = base64_encode(cond->fingerprint, 32);
|
||||
cJSON_AddItemToObject(params, "fingerprint", cJSON_CreateString(b64));
|
||||
free(b64);
|
||||
cJSON_AddItemToObject(params, "cost", cJSON_CreateNumber(cond->cost));
|
||||
cJSON_AddItemToObject(params, "subtypes", cJSON_CreateNumber(cond->subtypes));
|
||||
}
|
||||
|
||||
|
||||
static unsigned char *anonFingerprint(const CC *cond) {
|
||||
unsigned char *out = calloc(1, 32);
|
||||
memcpy(out, cond->fingerprint, 32);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
static unsigned long anonCost(const CC *cond) {
|
||||
return cond->cost;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t anonSubtypes(const CC *cond) {
|
||||
return cond->subtypes;
|
||||
}
|
||||
|
||||
|
||||
static Fulfillment_t *anonFulfillment(const CC *cond) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void anonFree(CC *cond) {
|
||||
}
|
||||
|
||||
|
||||
static int anonIsFulfilled(const CC *cond) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct CCType CC_AnonType = { -1, "(anon)", Condition_PR_NOTHING, NULL, &anonFingerprint, &anonCost, &anonSubtypes, NULL, &anonToJSON, NULL, &anonFulfillment, &anonIsFulfilled, &anonFree };
|
||||
189
src/cryptoconditions/src/asn/BIT_STRING.c
Normal file
189
src/cryptoconditions/src/asn/BIT_STRING.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/*-
|
||||
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
#include <asn_internal.h>
|
||||
#include <BIT_STRING.h>
|
||||
#include <asn_internal.h>
|
||||
|
||||
/*
|
||||
* BIT STRING basic type description.
|
||||
*/
|
||||
static const ber_tlv_tag_t asn_DEF_BIT_STRING_tags[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (3 << 2))
|
||||
};
|
||||
static asn_OCTET_STRING_specifics_t asn_DEF_BIT_STRING_specs = {
|
||||
sizeof(BIT_STRING_t),
|
||||
offsetof(BIT_STRING_t, _asn_ctx),
|
||||
ASN_OSUBV_BIT
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
|
||||
"BIT STRING",
|
||||
"BIT_STRING",
|
||||
OCTET_STRING_free, /* Implemented in terms of OCTET STRING */
|
||||
BIT_STRING_print,
|
||||
BIT_STRING_constraint,
|
||||
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
|
||||
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
|
||||
OCTET_STRING_decode_xer_binary,
|
||||
BIT_STRING_encode_xer,
|
||||
OCTET_STRING_decode_uper, /* Unaligned PER decoder */
|
||||
OCTET_STRING_encode_uper, /* Unaligned PER encoder */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_BIT_STRING_tags,
|
||||
sizeof(asn_DEF_BIT_STRING_tags)
|
||||
/ sizeof(asn_DEF_BIT_STRING_tags[0]),
|
||||
asn_DEF_BIT_STRING_tags, /* Same as above */
|
||||
sizeof(asn_DEF_BIT_STRING_tags)
|
||||
/ sizeof(asn_DEF_BIT_STRING_tags[0]),
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
&asn_DEF_BIT_STRING_specs
|
||||
};
|
||||
|
||||
/*
|
||||
* BIT STRING generic constraint.
|
||||
*/
|
||||
int
|
||||
BIT_STRING_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
|
||||
|
||||
if(st && st->buf) {
|
||||
if((st->size == 0 && st->bits_unused)
|
||||
|| st->bits_unused < 0 || st->bits_unused > 7) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: invalid padding byte (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *_bit_pattern[16] = {
|
||||
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
|
||||
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
|
||||
};
|
||||
|
||||
asn_enc_rval_t
|
||||
BIT_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
asn_enc_rval_t er;
|
||||
char scratch[128];
|
||||
char *p = scratch;
|
||||
char *scend = scratch + (sizeof(scratch) - 10);
|
||||
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
|
||||
int xcan = (flags & XER_F_CANONICAL);
|
||||
uint8_t *buf;
|
||||
uint8_t *end;
|
||||
|
||||
if(!st || !st->buf)
|
||||
ASN__ENCODE_FAILED;
|
||||
|
||||
er.encoded = 0;
|
||||
|
||||
buf = st->buf;
|
||||
end = buf + st->size - 1; /* Last byte is special */
|
||||
|
||||
/*
|
||||
* Binary dump
|
||||
*/
|
||||
for(; buf < end; buf++) {
|
||||
int v = *buf;
|
||||
int nline = xcan?0:(((buf - st->buf) % 8) == 0);
|
||||
if(p >= scend || nline) {
|
||||
er.encoded += p - scratch;
|
||||
ASN__CALLBACK(scratch, p - scratch);
|
||||
p = scratch;
|
||||
if(nline) ASN__TEXT_INDENT(1, ilevel);
|
||||
}
|
||||
memcpy(p + 0, _bit_pattern[v >> 4], 4);
|
||||
memcpy(p + 4, _bit_pattern[v & 0x0f], 4);
|
||||
p += 8;
|
||||
}
|
||||
|
||||
if(!xcan && ((buf - st->buf) % 8) == 0)
|
||||
ASN__TEXT_INDENT(1, ilevel);
|
||||
er.encoded += p - scratch;
|
||||
ASN__CALLBACK(scratch, p - scratch);
|
||||
p = scratch;
|
||||
|
||||
if(buf == end) {
|
||||
int v = *buf;
|
||||
int ubits = st->bits_unused;
|
||||
int i;
|
||||
for(i = 7; i >= ubits; i--)
|
||||
*p++ = (v & (1 << i)) ? 0x31 : 0x30;
|
||||
er.encoded += p - scratch;
|
||||
ASN__CALLBACK(scratch, p - scratch);
|
||||
}
|
||||
|
||||
if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1);
|
||||
|
||||
ASN__ENCODED_OK(er);
|
||||
cb_failed:
|
||||
ASN__ENCODE_FAILED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* BIT STRING specific contents printer.
|
||||
*/
|
||||
int
|
||||
BIT_STRING_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
const char * const h2c = "0123456789ABCDEF";
|
||||
char scratch[64];
|
||||
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
|
||||
uint8_t *buf;
|
||||
uint8_t *end;
|
||||
char *p = scratch;
|
||||
|
||||
(void)td; /* Unused argument */
|
||||
|
||||
if(!st || !st->buf)
|
||||
return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
|
||||
|
||||
ilevel++;
|
||||
buf = st->buf;
|
||||
end = buf + st->size;
|
||||
|
||||
/*
|
||||
* Hexadecimal dump.
|
||||
*/
|
||||
for(; buf < end; buf++) {
|
||||
if((buf - st->buf) % 16 == 0 && (st->size > 16)
|
||||
&& buf != st->buf) {
|
||||
_i_INDENT(1);
|
||||
/* Dump the string */
|
||||
if(cb(scratch, p - scratch, app_key) < 0) return -1;
|
||||
p = scratch;
|
||||
}
|
||||
*p++ = h2c[*buf >> 4];
|
||||
*p++ = h2c[*buf & 0x0F];
|
||||
*p++ = 0x20;
|
||||
}
|
||||
|
||||
if(p > scratch) {
|
||||
p--; /* Eat the tailing space */
|
||||
|
||||
if((st->size > 16)) {
|
||||
_i_INDENT(1);
|
||||
}
|
||||
|
||||
/* Dump the incomplete 16-bytes row */
|
||||
if(cb(scratch, p - scratch, app_key) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
33
src/cryptoconditions/src/asn/BIT_STRING.h
Normal file
33
src/cryptoconditions/src/asn/BIT_STRING.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*-
|
||||
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
#ifndef _BIT_STRING_H_
|
||||
#define _BIT_STRING_H_
|
||||
|
||||
#include <OCTET_STRING.h> /* Some help from OCTET STRING */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct BIT_STRING_s {
|
||||
uint8_t *buf; /* BIT STRING body */
|
||||
int size; /* Size of the above buffer */
|
||||
|
||||
int bits_unused;/* Unused trailing bits in the last octet (0..7) */
|
||||
|
||||
asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
|
||||
} BIT_STRING_t;
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_BIT_STRING;
|
||||
|
||||
asn_struct_print_f BIT_STRING_print; /* Human-readable output */
|
||||
asn_constr_check_f BIT_STRING_constraint;
|
||||
xer_type_encoder_f BIT_STRING_encode_xer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BIT_STRING_H_ */
|
||||
235
src/cryptoconditions/src/asn/CompoundSha256Condition.c
Normal file
235
src/cryptoconditions/src/asn/CompoundSha256Condition.c
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "CompoundSha256Condition.h"
|
||||
|
||||
static int
|
||||
cost_3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This type is implemented using NativeInteger,
|
||||
* so here we adjust the DEF accordingly.
|
||||
*/
|
||||
static void
|
||||
cost_3_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {
|
||||
td->free_struct = asn_DEF_NativeInteger.free_struct;
|
||||
td->print_struct = asn_DEF_NativeInteger.print_struct;
|
||||
td->check_constraints = asn_DEF_NativeInteger.check_constraints;
|
||||
td->ber_decoder = asn_DEF_NativeInteger.ber_decoder;
|
||||
td->der_encoder = asn_DEF_NativeInteger.der_encoder;
|
||||
td->xer_decoder = asn_DEF_NativeInteger.xer_decoder;
|
||||
td->xer_encoder = asn_DEF_NativeInteger.xer_encoder;
|
||||
td->uper_decoder = asn_DEF_NativeInteger.uper_decoder;
|
||||
td->uper_encoder = asn_DEF_NativeInteger.uper_encoder;
|
||||
if(!td->per_constraints)
|
||||
td->per_constraints = asn_DEF_NativeInteger.per_constraints;
|
||||
td->elements = asn_DEF_NativeInteger.elements;
|
||||
td->elements_count = asn_DEF_NativeInteger.elements_count;
|
||||
/* td->specifics = asn_DEF_NativeInteger.specifics; // Defined explicitly */
|
||||
}
|
||||
|
||||
static void
|
||||
cost_3_free(asn_TYPE_descriptor_t *td,
|
||||
void *struct_ptr, int contents_only) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
td->free_struct(td, struct_ptr, contents_only);
|
||||
}
|
||||
|
||||
static int
|
||||
cost_3_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,
|
||||
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
cost_3_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const void *bufptr, size_t size, int tag_mode) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
cost_3_encode_der(asn_TYPE_descriptor_t *td,
|
||||
void *structure, int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
cost_3_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const char *opt_mname, const void *bufptr, size_t size) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
cost_3_encode_xer(asn_TYPE_descriptor_t *td, void *structure,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
|
||||
}
|
||||
|
||||
static int
|
||||
memb_fingerprint_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 32)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memb_cost_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const asn_INTEGER_specifics_t asn_SPC_cost_specs_3 = {
|
||||
0, 0, 0, 0, 0,
|
||||
0, /* Native long size */
|
||||
1 /* Unsigned representation */
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_cost_tags_3[] = {
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
|
||||
};
|
||||
static /* Use -fall-defs-global to expose */
|
||||
asn_TYPE_descriptor_t asn_DEF_cost_3 = {
|
||||
"cost",
|
||||
"cost",
|
||||
cost_3_free,
|
||||
cost_3_print,
|
||||
cost_3_constraint,
|
||||
cost_3_decode_ber,
|
||||
cost_3_encode_der,
|
||||
cost_3_decode_xer,
|
||||
cost_3_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_cost_tags_3,
|
||||
sizeof(asn_DEF_cost_tags_3)
|
||||
/sizeof(asn_DEF_cost_tags_3[0]) - 1, /* 1 */
|
||||
asn_DEF_cost_tags_3, /* Same as above */
|
||||
sizeof(asn_DEF_cost_tags_3)
|
||||
/sizeof(asn_DEF_cost_tags_3[0]), /* 2 */
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
&asn_SPC_cost_specs_3 /* Additional specs */
|
||||
};
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_CompoundSha256Condition_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct CompoundSha256Condition, fingerprint),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_fingerprint_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"fingerprint"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct CompoundSha256Condition, cost),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_cost_3,
|
||||
memb_cost_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"cost"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct CompoundSha256Condition, subtypes),
|
||||
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_ConditionTypes,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"subtypes"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_CompoundSha256Condition_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_CompoundSha256Condition_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* fingerprint */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* cost */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* subtypes */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_CompoundSha256Condition_specs_1 = {
|
||||
sizeof(struct CompoundSha256Condition),
|
||||
offsetof(struct CompoundSha256Condition, _asn_ctx),
|
||||
asn_MAP_CompoundSha256Condition_tag2el_1,
|
||||
3, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_CompoundSha256Condition = {
|
||||
"CompoundSha256Condition",
|
||||
"CompoundSha256Condition",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_CompoundSha256Condition_tags_1,
|
||||
sizeof(asn_DEF_CompoundSha256Condition_tags_1)
|
||||
/sizeof(asn_DEF_CompoundSha256Condition_tags_1[0]), /* 1 */
|
||||
asn_DEF_CompoundSha256Condition_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_CompoundSha256Condition_tags_1)
|
||||
/sizeof(asn_DEF_CompoundSha256Condition_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_CompoundSha256Condition_1,
|
||||
3, /* Elements count */
|
||||
&asn_SPC_CompoundSha256Condition_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
42
src/cryptoconditions/src/asn/CompoundSha256Condition.h
Normal file
42
src/cryptoconditions/src/asn/CompoundSha256Condition.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _CompoundSha256Condition_H_
|
||||
#define _CompoundSha256Condition_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <NativeInteger.h>
|
||||
#include "ConditionTypes.h"
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* CompoundSha256Condition */
|
||||
typedef struct CompoundSha256Condition {
|
||||
OCTET_STRING_t fingerprint;
|
||||
unsigned long cost;
|
||||
ConditionTypes_t subtypes;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} CompoundSha256Condition_t;
|
||||
|
||||
/* Implementation */
|
||||
/* extern asn_TYPE_descriptor_t asn_DEF_cost_3; // (Use -fall-defs-global to expose) */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_CompoundSha256Condition;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CompoundSha256Condition_H_ */
|
||||
#include <asn_internal.h>
|
||||
114
src/cryptoconditions/src/asn/Condition.c
Normal file
114
src/cryptoconditions/src/asn/Condition.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "Condition.h"
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_Condition_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.preimageSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_SimpleSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"preimageSha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.prefixSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_CompoundSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"prefixSha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.thresholdSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_CompoundSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"thresholdSha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.rsaSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (3 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_SimpleSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"rsaSha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.ed25519Sha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (4 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_SimpleSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"ed25519Sha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.secp256k1Sha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (5 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_SimpleSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"secp256k1Sha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Condition, choice.evalSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (15 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_SimpleSha256Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"evalSha256"
|
||||
},
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_Condition_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* preimageSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* prefixSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 }, /* thresholdSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 3, 0, 0 }, /* rsaSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (4 << 2)), 4, 0, 0 }, /* ed25519Sha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 5, 0, 0 }, /* secp256k1Sha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (15 << 2)), 6, 0, 0 } /* evalSha256 */
|
||||
};
|
||||
static asn_CHOICE_specifics_t asn_SPC_Condition_specs_1 = {
|
||||
sizeof(struct Condition),
|
||||
offsetof(struct Condition, _asn_ctx),
|
||||
offsetof(struct Condition, present),
|
||||
sizeof(((struct Condition *)0)->present),
|
||||
asn_MAP_Condition_tag2el_1,
|
||||
7, /* Count of tags in the map */
|
||||
0,
|
||||
-1 /* Extensions start */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_Condition = {
|
||||
"Condition",
|
||||
"Condition",
|
||||
CHOICE_free,
|
||||
CHOICE_print,
|
||||
CHOICE_constraint,
|
||||
CHOICE_decode_ber,
|
||||
CHOICE_encode_der,
|
||||
CHOICE_decode_xer,
|
||||
CHOICE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
CHOICE_outmost_tag,
|
||||
0, /* No effective tags (pointer) */
|
||||
0, /* No effective tags (count) */
|
||||
0, /* No tags (pointer) */
|
||||
0, /* No tags (count) */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_Condition_1,
|
||||
7, /* Elements count */
|
||||
&asn_SPC_Condition_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
59
src/cryptoconditions/src/asn/Condition.h
Normal file
59
src/cryptoconditions/src/asn/Condition.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _Condition_H_
|
||||
#define _Condition_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include "SimpleSha256Condition.h"
|
||||
#include "CompoundSha256Condition.h"
|
||||
#include <constr_CHOICE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Dependencies */
|
||||
typedef enum Condition_PR {
|
||||
Condition_PR_NOTHING, /* No components present */
|
||||
Condition_PR_preimageSha256,
|
||||
Condition_PR_prefixSha256,
|
||||
Condition_PR_thresholdSha256,
|
||||
Condition_PR_rsaSha256,
|
||||
Condition_PR_ed25519Sha256,
|
||||
Condition_PR_secp256k1Sha256,
|
||||
Condition_PR_evalSha256
|
||||
} Condition_PR;
|
||||
|
||||
/* Condition */
|
||||
typedef struct Condition {
|
||||
Condition_PR present;
|
||||
union Condition_u {
|
||||
SimpleSha256Condition_t preimageSha256;
|
||||
CompoundSha256Condition_t prefixSha256;
|
||||
CompoundSha256Condition_t thresholdSha256;
|
||||
SimpleSha256Condition_t rsaSha256;
|
||||
SimpleSha256Condition_t ed25519Sha256;
|
||||
SimpleSha256Condition_t secp256k1Sha256;
|
||||
SimpleSha256Condition_t evalSha256;
|
||||
} choice;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} Condition_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_Condition;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _Condition_H_ */
|
||||
#include <asn_internal.h>
|
||||
108
src/cryptoconditions/src/asn/ConditionTypes.c
Normal file
108
src/cryptoconditions/src/asn/ConditionTypes.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "ConditionTypes.h"
|
||||
|
||||
int
|
||||
ConditionTypes_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
/* Replace with underlying type checker */
|
||||
td->check_constraints = asn_DEF_BIT_STRING.check_constraints;
|
||||
return td->check_constraints(td, sptr, ctfailcb, app_key);
|
||||
}
|
||||
|
||||
/*
|
||||
* This type is implemented using BIT_STRING,
|
||||
* so here we adjust the DEF accordingly.
|
||||
*/
|
||||
static void
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {
|
||||
td->free_struct = asn_DEF_BIT_STRING.free_struct;
|
||||
td->print_struct = asn_DEF_BIT_STRING.print_struct;
|
||||
td->check_constraints = asn_DEF_BIT_STRING.check_constraints;
|
||||
td->ber_decoder = asn_DEF_BIT_STRING.ber_decoder;
|
||||
td->der_encoder = asn_DEF_BIT_STRING.der_encoder;
|
||||
td->xer_decoder = asn_DEF_BIT_STRING.xer_decoder;
|
||||
td->xer_encoder = asn_DEF_BIT_STRING.xer_encoder;
|
||||
td->uper_decoder = asn_DEF_BIT_STRING.uper_decoder;
|
||||
td->uper_encoder = asn_DEF_BIT_STRING.uper_encoder;
|
||||
if(!td->per_constraints)
|
||||
td->per_constraints = asn_DEF_BIT_STRING.per_constraints;
|
||||
td->elements = asn_DEF_BIT_STRING.elements;
|
||||
td->elements_count = asn_DEF_BIT_STRING.elements_count;
|
||||
td->specifics = asn_DEF_BIT_STRING.specifics;
|
||||
}
|
||||
|
||||
void
|
||||
ConditionTypes_free(asn_TYPE_descriptor_t *td,
|
||||
void *struct_ptr, int contents_only) {
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(td);
|
||||
td->free_struct(td, struct_ptr, contents_only);
|
||||
}
|
||||
|
||||
int
|
||||
ConditionTypes_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,
|
||||
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(td);
|
||||
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
|
||||
}
|
||||
|
||||
asn_dec_rval_t
|
||||
ConditionTypes_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const void *bufptr, size_t size, int tag_mode) {
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(td);
|
||||
return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);
|
||||
}
|
||||
|
||||
asn_enc_rval_t
|
||||
ConditionTypes_encode_der(asn_TYPE_descriptor_t *td,
|
||||
void *structure, int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(td);
|
||||
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
|
||||
}
|
||||
|
||||
asn_dec_rval_t
|
||||
ConditionTypes_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const char *opt_mname, const void *bufptr, size_t size) {
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(td);
|
||||
return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);
|
||||
}
|
||||
|
||||
asn_enc_rval_t
|
||||
ConditionTypes_encode_xer(asn_TYPE_descriptor_t *td, void *structure,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
ConditionTypes_1_inherit_TYPE_descriptor(td);
|
||||
return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
|
||||
}
|
||||
|
||||
static const ber_tlv_tag_t asn_DEF_ConditionTypes_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (3 << 2))
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_ConditionTypes = {
|
||||
"ConditionTypes",
|
||||
"ConditionTypes",
|
||||
ConditionTypes_free,
|
||||
ConditionTypes_print,
|
||||
ConditionTypes_constraint,
|
||||
ConditionTypes_decode_ber,
|
||||
ConditionTypes_encode_der,
|
||||
ConditionTypes_decode_xer,
|
||||
ConditionTypes_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_ConditionTypes_tags_1,
|
||||
sizeof(asn_DEF_ConditionTypes_tags_1)
|
||||
/sizeof(asn_DEF_ConditionTypes_tags_1[0]), /* 1 */
|
||||
asn_DEF_ConditionTypes_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_ConditionTypes_tags_1)
|
||||
/sizeof(asn_DEF_ConditionTypes_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* Defined elsewhere */
|
||||
0 /* No specifics */
|
||||
};
|
||||
|
||||
49
src/cryptoconditions/src/asn/ConditionTypes.h
Normal file
49
src/cryptoconditions/src/asn/ConditionTypes.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _ConditionTypes_H_
|
||||
#define _ConditionTypes_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <BIT_STRING.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Dependencies */
|
||||
typedef enum ConditionTypes {
|
||||
ConditionTypes_preImageSha256 = 0,
|
||||
ConditionTypes_prefixSha256 = 1,
|
||||
ConditionTypes_thresholdSha256 = 2,
|
||||
ConditionTypes_rsaSha256 = 3,
|
||||
ConditionTypes_ed25519Sha256 = 4,
|
||||
ConditionTypes_secp256k1Sha256 = 5,
|
||||
ConditionTypes_evalSha256 = 15
|
||||
} e_ConditionTypes;
|
||||
|
||||
/* ConditionTypes */
|
||||
typedef BIT_STRING_t ConditionTypes_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_ConditionTypes;
|
||||
asn_struct_free_f ConditionTypes_free;
|
||||
asn_struct_print_f ConditionTypes_print;
|
||||
asn_constr_check_f ConditionTypes_constraint;
|
||||
ber_type_decoder_f ConditionTypes_decode_ber;
|
||||
der_type_encoder_f ConditionTypes_encode_der;
|
||||
xer_type_decoder_f ConditionTypes_decode_xer;
|
||||
xer_type_encoder_f ConditionTypes_encode_xer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ConditionTypes_H_ */
|
||||
#include <asn_internal.h>
|
||||
113
src/cryptoconditions/src/asn/CryptoConditions.asn
Normal file
113
src/cryptoconditions/src/asn/CryptoConditions.asn
Normal file
@@ -0,0 +1,113 @@
|
||||
--<ASN1.PDU Crypto-Conditions.Condition, Crypto-Conditions.Fulfillment>--
|
||||
|
||||
Crypto-Conditions DEFINITIONS AUTOMATIC TAGS ::= BEGIN
|
||||
|
||||
-- Conditions
|
||||
|
||||
Condition ::= CHOICE {
|
||||
preimageSha256 [0] SimpleSha256Condition,
|
||||
prefixSha256 [1] CompoundSha256Condition,
|
||||
thresholdSha256 [2] CompoundSha256Condition,
|
||||
rsaSha256 [3] SimpleSha256Condition,
|
||||
ed25519Sha256 [4] SimpleSha256Condition,
|
||||
secp256k1Sha256 [5] SimpleSha256Condition,
|
||||
evalSha256 [15] SimpleSha256Condition
|
||||
}
|
||||
|
||||
SimpleSha256Condition ::= SEQUENCE {
|
||||
fingerprint OCTET STRING (SIZE(32)),
|
||||
cost INTEGER (0..4294967295)
|
||||
}
|
||||
|
||||
CompoundSha256Condition ::= SEQUENCE {
|
||||
fingerprint OCTET STRING (SIZE(32)),
|
||||
cost INTEGER (0..4294967295),
|
||||
subtypes ConditionTypes
|
||||
}
|
||||
|
||||
ConditionTypes ::= BIT STRING {
|
||||
preImageSha256 (0),
|
||||
prefixSha256 (1),
|
||||
thresholdSha256 (2),
|
||||
rsaSha256 (3),
|
||||
ed25519Sha256 (4),
|
||||
secp256k1Sha256 (5),
|
||||
evalSha256 (15)
|
||||
}
|
||||
|
||||
-- Fulfillments
|
||||
|
||||
Fulfillment ::= CHOICE {
|
||||
preimageSha256 [0] PreimageFulfillment ,
|
||||
prefixSha256 [1] PrefixFulfillment,
|
||||
thresholdSha256 [2] ThresholdFulfillment,
|
||||
rsaSha256 [3] RsaSha256Fulfillment,
|
||||
ed25519Sha256 [4] Ed25519Sha512Fulfillment,
|
||||
secp256k1Sha256 [5] Secp256k1Fulfillment,
|
||||
evalSha256 [15] EvalFulfillment
|
||||
}
|
||||
|
||||
PreimageFulfillment ::= SEQUENCE {
|
||||
preimage OCTET STRING
|
||||
}
|
||||
|
||||
PrefixFulfillment ::= SEQUENCE {
|
||||
prefix OCTET STRING,
|
||||
maxMessageLength INTEGER (0..4294967295),
|
||||
subfulfillment Fulfillment
|
||||
}
|
||||
|
||||
ThresholdFulfillment ::= SEQUENCE {
|
||||
subfulfillments SET OF Fulfillment,
|
||||
subconditions SET OF Condition
|
||||
}
|
||||
|
||||
RsaSha256Fulfillment ::= SEQUENCE {
|
||||
modulus OCTET STRING,
|
||||
signature OCTET STRING
|
||||
}
|
||||
|
||||
Ed25519Sha512Fulfillment ::= SEQUENCE {
|
||||
publicKey OCTET STRING (SIZE(32)),
|
||||
signature OCTET STRING (SIZE(64))
|
||||
}
|
||||
|
||||
Secp256k1Fulfillment ::= SEQUENCE {
|
||||
publicKey OCTET STRING (SIZE(33)),
|
||||
signature OCTET STRING (SIZE(64))
|
||||
}
|
||||
|
||||
EvalFulfillment ::= SEQUENCE {
|
||||
code OCTET STRING
|
||||
}
|
||||
|
||||
-- Fingerprint Content
|
||||
|
||||
-- The PREIMAGE-SHA-256 condition fingerprint content is not DER encoded
|
||||
-- The fingerprint content is the preimage
|
||||
-- Same for Eval
|
||||
|
||||
PrefixFingerprintContents ::= SEQUENCE {
|
||||
prefix OCTET STRING,
|
||||
maxMessageLength INTEGER (0..4294967295),
|
||||
subcondition Condition
|
||||
}
|
||||
|
||||
ThresholdFingerprintContents ::= SEQUENCE {
|
||||
threshold INTEGER (1..65535),
|
||||
subconditions2 SET OF Condition
|
||||
}
|
||||
|
||||
RsaFingerprintContents ::= SEQUENCE {
|
||||
modulus OCTET STRING
|
||||
}
|
||||
|
||||
Ed25519FingerprintContents ::= SEQUENCE {
|
||||
publicKey OCTET STRING (SIZE(32))
|
||||
}
|
||||
|
||||
Secp256k1FingerprintContents ::= SEQUENCE {
|
||||
publicKey OCTET STRING (SIZE(33))
|
||||
}
|
||||
|
||||
END
|
||||
84
src/cryptoconditions/src/asn/Ed25519FingerprintContents.c
Normal file
84
src/cryptoconditions/src/asn/Ed25519FingerprintContents.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "Ed25519FingerprintContents.h"
|
||||
|
||||
static int
|
||||
memb_publicKey_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 32)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_Ed25519FingerprintContents_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Ed25519FingerprintContents, publicKey),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_publicKey_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"publicKey"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_Ed25519FingerprintContents_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_Ed25519FingerprintContents_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* publicKey */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_Ed25519FingerprintContents_specs_1 = {
|
||||
sizeof(struct Ed25519FingerprintContents),
|
||||
offsetof(struct Ed25519FingerprintContents, _asn_ctx),
|
||||
asn_MAP_Ed25519FingerprintContents_tag2el_1,
|
||||
1, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_Ed25519FingerprintContents = {
|
||||
"Ed25519FingerprintContents",
|
||||
"Ed25519FingerprintContents",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_Ed25519FingerprintContents_tags_1,
|
||||
sizeof(asn_DEF_Ed25519FingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_Ed25519FingerprintContents_tags_1[0]), /* 1 */
|
||||
asn_DEF_Ed25519FingerprintContents_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_Ed25519FingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_Ed25519FingerprintContents_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_Ed25519FingerprintContents_1,
|
||||
1, /* Elements count */
|
||||
&asn_SPC_Ed25519FingerprintContents_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
37
src/cryptoconditions/src/asn/Ed25519FingerprintContents.h
Normal file
37
src/cryptoconditions/src/asn/Ed25519FingerprintContents.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _Ed25519FingerprintContents_H_
|
||||
#define _Ed25519FingerprintContents_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Ed25519FingerprintContents */
|
||||
typedef struct Ed25519FingerprintContents {
|
||||
OCTET_STRING_t publicKey;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} Ed25519FingerprintContents_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_Ed25519FingerprintContents;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _Ed25519FingerprintContents_H_ */
|
||||
#include <asn_internal.h>
|
||||
120
src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c
Normal file
120
src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "Ed25519Sha512Fulfillment.h"
|
||||
|
||||
static int
|
||||
memb_publicKey_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 32)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memb_signature_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 64)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_Ed25519Sha512Fulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Ed25519Sha512Fulfillment, publicKey),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_publicKey_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"publicKey"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Ed25519Sha512Fulfillment, signature),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_signature_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"signature"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_Ed25519Sha512Fulfillment_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_Ed25519Sha512Fulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* publicKey */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* signature */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_Ed25519Sha512Fulfillment_specs_1 = {
|
||||
sizeof(struct Ed25519Sha512Fulfillment),
|
||||
offsetof(struct Ed25519Sha512Fulfillment, _asn_ctx),
|
||||
asn_MAP_Ed25519Sha512Fulfillment_tag2el_1,
|
||||
2, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_Ed25519Sha512Fulfillment = {
|
||||
"Ed25519Sha512Fulfillment",
|
||||
"Ed25519Sha512Fulfillment",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_Ed25519Sha512Fulfillment_tags_1,
|
||||
sizeof(asn_DEF_Ed25519Sha512Fulfillment_tags_1)
|
||||
/sizeof(asn_DEF_Ed25519Sha512Fulfillment_tags_1[0]), /* 1 */
|
||||
asn_DEF_Ed25519Sha512Fulfillment_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_Ed25519Sha512Fulfillment_tags_1)
|
||||
/sizeof(asn_DEF_Ed25519Sha512Fulfillment_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_Ed25519Sha512Fulfillment_1,
|
||||
2, /* Elements count */
|
||||
&asn_SPC_Ed25519Sha512Fulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
38
src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h
Normal file
38
src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _Ed25519Sha512Fulfillment_H_
|
||||
#define _Ed25519Sha512Fulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Ed25519Sha512Fulfillment */
|
||||
typedef struct Ed25519Sha512Fulfillment {
|
||||
OCTET_STRING_t publicKey;
|
||||
OCTET_STRING_t signature;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} Ed25519Sha512Fulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_Ed25519Sha512Fulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _Ed25519Sha512Fulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
58
src/cryptoconditions/src/asn/EvalFulfillment.c
Normal file
58
src/cryptoconditions/src/asn/EvalFulfillment.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "EvalFulfillment.h"
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_EvalFulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct EvalFulfillment, code),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"code"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_EvalFulfillment_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_EvalFulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* code */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_EvalFulfillment_specs_1 = {
|
||||
sizeof(struct EvalFulfillment),
|
||||
offsetof(struct EvalFulfillment, _asn_ctx),
|
||||
asn_MAP_EvalFulfillment_tag2el_1,
|
||||
1, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_EvalFulfillment = {
|
||||
"EvalFulfillment",
|
||||
"EvalFulfillment",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_EvalFulfillment_tags_1,
|
||||
sizeof(asn_DEF_EvalFulfillment_tags_1)
|
||||
/sizeof(asn_DEF_EvalFulfillment_tags_1[0]), /* 1 */
|
||||
asn_DEF_EvalFulfillment_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_EvalFulfillment_tags_1)
|
||||
/sizeof(asn_DEF_EvalFulfillment_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_EvalFulfillment_1,
|
||||
1, /* Elements count */
|
||||
&asn_SPC_EvalFulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
37
src/cryptoconditions/src/asn/EvalFulfillment.h
Normal file
37
src/cryptoconditions/src/asn/EvalFulfillment.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _EvalFulfillment_H_
|
||||
#define _EvalFulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* EvalFulfillment */
|
||||
typedef struct EvalFulfillment {
|
||||
OCTET_STRING_t code;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} EvalFulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_EvalFulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _EvalFulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
114
src/cryptoconditions/src/asn/Fulfillment.c
Normal file
114
src/cryptoconditions/src/asn/Fulfillment.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "Fulfillment.h"
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_Fulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Fulfillment, choice.preimageSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_PreimageFulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"preimageSha256"
|
||||
},
|
||||
{ ATF_POINTER, 0, offsetof(struct Fulfillment, choice.prefixSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_PrefixFulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"prefixSha256"
|
||||
},
|
||||
{ ATF_POINTER, 0, offsetof(struct Fulfillment, choice.thresholdSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_ThresholdFulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"thresholdSha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Fulfillment, choice.rsaSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (3 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_RsaSha256Fulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"rsaSha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Fulfillment, choice.ed25519Sha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (4 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_Ed25519Sha512Fulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"ed25519Sha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Fulfillment, choice.secp256k1Sha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (5 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_Secp256k1Fulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"secp256k1Sha256"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Fulfillment, choice.evalSha256),
|
||||
(ASN_TAG_CLASS_CONTEXT | (15 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_EvalFulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"evalSha256"
|
||||
},
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_Fulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* preimageSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* prefixSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 }, /* thresholdSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 3, 0, 0 }, /* rsaSha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (4 << 2)), 4, 0, 0 }, /* ed25519Sha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 5, 0, 0 }, /* secp256k1Sha256 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (15 << 2)), 6, 0, 0 } /* evalSha256 */
|
||||
};
|
||||
static asn_CHOICE_specifics_t asn_SPC_Fulfillment_specs_1 = {
|
||||
sizeof(struct Fulfillment),
|
||||
offsetof(struct Fulfillment, _asn_ctx),
|
||||
offsetof(struct Fulfillment, present),
|
||||
sizeof(((struct Fulfillment *)0)->present),
|
||||
asn_MAP_Fulfillment_tag2el_1,
|
||||
7, /* Count of tags in the map */
|
||||
0,
|
||||
-1 /* Extensions start */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_Fulfillment = {
|
||||
"Fulfillment",
|
||||
"Fulfillment",
|
||||
CHOICE_free,
|
||||
CHOICE_print,
|
||||
CHOICE_constraint,
|
||||
CHOICE_decode_ber,
|
||||
CHOICE_encode_der,
|
||||
CHOICE_decode_xer,
|
||||
CHOICE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
CHOICE_outmost_tag,
|
||||
0, /* No effective tags (pointer) */
|
||||
0, /* No effective tags (count) */
|
||||
0, /* No tags (pointer) */
|
||||
0, /* No tags (count) */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_Fulfillment_1,
|
||||
7, /* Elements count */
|
||||
&asn_SPC_Fulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
70
src/cryptoconditions/src/asn/Fulfillment.h
Normal file
70
src/cryptoconditions/src/asn/Fulfillment.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _Fulfillment_H_
|
||||
#define _Fulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include "PreimageFulfillment.h"
|
||||
#include "RsaSha256Fulfillment.h"
|
||||
#include "Ed25519Sha512Fulfillment.h"
|
||||
#include "Secp256k1Fulfillment.h"
|
||||
#include "EvalFulfillment.h"
|
||||
#include <constr_CHOICE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Dependencies */
|
||||
typedef enum Fulfillment_PR {
|
||||
Fulfillment_PR_NOTHING, /* No components present */
|
||||
Fulfillment_PR_preimageSha256,
|
||||
Fulfillment_PR_prefixSha256,
|
||||
Fulfillment_PR_thresholdSha256,
|
||||
Fulfillment_PR_rsaSha256,
|
||||
Fulfillment_PR_ed25519Sha256,
|
||||
Fulfillment_PR_secp256k1Sha256,
|
||||
Fulfillment_PR_evalSha256
|
||||
} Fulfillment_PR;
|
||||
|
||||
/* Forward declarations */
|
||||
struct PrefixFulfillment;
|
||||
struct ThresholdFulfillment;
|
||||
|
||||
/* Fulfillment */
|
||||
typedef struct Fulfillment {
|
||||
Fulfillment_PR present;
|
||||
union Fulfillment_u {
|
||||
PreimageFulfillment_t preimageSha256;
|
||||
struct PrefixFulfillment *prefixSha256;
|
||||
struct ThresholdFulfillment *thresholdSha256;
|
||||
RsaSha256Fulfillment_t rsaSha256;
|
||||
Ed25519Sha512Fulfillment_t ed25519Sha256;
|
||||
Secp256k1Fulfillment_t secp256k1Sha256;
|
||||
EvalFulfillment_t evalSha256;
|
||||
} choice;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} Fulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_Fulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Referred external types */
|
||||
#include "PrefixFulfillment.h"
|
||||
#include "ThresholdFulfillment.h"
|
||||
|
||||
#endif /* _Fulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
1025
src/cryptoconditions/src/asn/INTEGER.c
Normal file
1025
src/cryptoconditions/src/asn/INTEGER.c
Normal file
File diff suppressed because it is too large
Load Diff
82
src/cryptoconditions/src/asn/INTEGER.h
Normal file
82
src/cryptoconditions/src/asn/INTEGER.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*-
|
||||
* Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
#ifndef _INTEGER_H_
|
||||
#define _INTEGER_H_
|
||||
|
||||
#include <asn_application.h>
|
||||
#include <asn_codecs_prim.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
|
||||
|
||||
/* Map with <tag> to integer value association */
|
||||
typedef struct asn_INTEGER_enum_map_s {
|
||||
long nat_value; /* associated native integer value */
|
||||
size_t enum_len; /* strlen("tag") */
|
||||
const char *enum_name; /* "tag" */
|
||||
} asn_INTEGER_enum_map_t;
|
||||
|
||||
/* This type describes an enumeration for INTEGER and ENUMERATED types */
|
||||
typedef const struct asn_INTEGER_specifics_s {
|
||||
const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
|
||||
const unsigned int *enum2value; /* "tag" => N; sorted by tag */
|
||||
int map_count; /* Elements in either map */
|
||||
int extension; /* This map is extensible */
|
||||
int strict_enumeration; /* Enumeration set is fixed */
|
||||
int field_width; /* Size of native integer */
|
||||
int field_unsigned; /* Signed=0, unsigned=1 */
|
||||
} asn_INTEGER_specifics_t;
|
||||
|
||||
asn_struct_print_f INTEGER_print;
|
||||
ber_type_decoder_f INTEGER_decode_ber;
|
||||
der_type_encoder_f INTEGER_encode_der;
|
||||
xer_type_decoder_f INTEGER_decode_xer;
|
||||
xer_type_encoder_f INTEGER_encode_xer;
|
||||
per_type_decoder_f INTEGER_decode_uper;
|
||||
per_type_encoder_f INTEGER_encode_uper;
|
||||
|
||||
/***********************************
|
||||
* Some handy conversion routines. *
|
||||
***********************************/
|
||||
|
||||
/*
|
||||
* Returns 0 if it was possible to convert, -1 otherwise.
|
||||
* -1/EINVAL: Mandatory argument missing
|
||||
* -1/ERANGE: Value encoded is out of range for long representation
|
||||
* -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()).
|
||||
*/
|
||||
int asn_INTEGER2long(const INTEGER_t *i, long *l);
|
||||
int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
|
||||
int asn_long2INTEGER(INTEGER_t *i, long l);
|
||||
int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
|
||||
|
||||
/* A a reified version of strtol(3) with nicer error reporting. */
|
||||
enum asn_strtol_result_e {
|
||||
ASN_STRTOL_ERROR_RANGE = -3, /* Input outside of numeric range for long type */
|
||||
ASN_STRTOL_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
|
||||
ASN_STRTOL_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
|
||||
ASN_STRTOL_OK = 0, /* Conversion succeded, number ends at (*end) */
|
||||
ASN_STRTOL_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */
|
||||
};
|
||||
enum asn_strtol_result_e asn_strtol_lim(const char *str, const char **end, long *l);
|
||||
|
||||
/* The asn_strtol is going to be DEPRECATED soon */
|
||||
enum asn_strtol_result_e asn_strtol(const char *str, const char *end, long *l);
|
||||
|
||||
/*
|
||||
* Convert the integer value into the corresponding enumeration map entry.
|
||||
*/
|
||||
const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INTEGER_H_ */
|
||||
120
src/cryptoconditions/src/asn/Makefile.am.sample
Normal file
120
src/cryptoconditions/src/asn/Makefile.am.sample
Normal file
@@ -0,0 +1,120 @@
|
||||
ASN_MODULE_SOURCES= \
|
||||
Condition.c \
|
||||
SimpleSha256Condition.c \
|
||||
CompoundSha256Condition.c \
|
||||
ConditionTypes.c \
|
||||
Fulfillment.c \
|
||||
PreimageFulfillment.c \
|
||||
PrefixFulfillment.c \
|
||||
ThresholdFulfillment.c \
|
||||
RsaSha256Fulfillment.c \
|
||||
Ed25519Sha512Fulfillment.c \
|
||||
Secp256k1Fulfillment.c \
|
||||
EvalFulfillment.c \
|
||||
PrefixFingerprintContents.c \
|
||||
ThresholdFingerprintContents.c \
|
||||
RsaFingerprintContents.c \
|
||||
Ed25519FingerprintContents.c \
|
||||
Secp256k1FingerprintContents.c
|
||||
|
||||
ASN_MODULE_HEADERS= \
|
||||
Condition.h \
|
||||
SimpleSha256Condition.h \
|
||||
CompoundSha256Condition.h \
|
||||
ConditionTypes.h \
|
||||
Fulfillment.h \
|
||||
PreimageFulfillment.h \
|
||||
PrefixFulfillment.h \
|
||||
ThresholdFulfillment.h \
|
||||
RsaSha256Fulfillment.h \
|
||||
Ed25519Sha512Fulfillment.h \
|
||||
Secp256k1Fulfillment.h \
|
||||
EvalFulfillment.h \
|
||||
PrefixFingerprintContents.h \
|
||||
ThresholdFingerprintContents.h \
|
||||
RsaFingerprintContents.h \
|
||||
Ed25519FingerprintContents.h \
|
||||
Secp256k1FingerprintContents.h
|
||||
|
||||
ASN_MODULE_HEADERS+=INTEGER.h
|
||||
ASN_MODULE_HEADERS+=NativeEnumerated.h
|
||||
ASN_MODULE_SOURCES+=INTEGER.c
|
||||
ASN_MODULE_SOURCES+=NativeEnumerated.c
|
||||
ASN_MODULE_HEADERS+=NativeInteger.h
|
||||
ASN_MODULE_SOURCES+=NativeInteger.c
|
||||
ASN_MODULE_HEADERS+=asn_SET_OF.h
|
||||
ASN_MODULE_SOURCES+=asn_SET_OF.c
|
||||
ASN_MODULE_HEADERS+=constr_CHOICE.h
|
||||
ASN_MODULE_SOURCES+=constr_CHOICE.c
|
||||
ASN_MODULE_HEADERS+=constr_SEQUENCE.h
|
||||
ASN_MODULE_SOURCES+=constr_SEQUENCE.c
|
||||
ASN_MODULE_HEADERS+=constr_SET_OF.h
|
||||
ASN_MODULE_SOURCES+=constr_SET_OF.c
|
||||
ASN_MODULE_HEADERS+=asn_application.h
|
||||
ASN_MODULE_HEADERS+=asn_system.h
|
||||
ASN_MODULE_HEADERS+=asn_codecs.h
|
||||
ASN_MODULE_HEADERS+=asn_internal.h
|
||||
ASN_MODULE_HEADERS+=OCTET_STRING.h
|
||||
ASN_MODULE_SOURCES+=OCTET_STRING.c
|
||||
ASN_MODULE_HEADERS+=BIT_STRING.h
|
||||
ASN_MODULE_SOURCES+=BIT_STRING.c
|
||||
ASN_MODULE_SOURCES+=asn_codecs_prim.c
|
||||
ASN_MODULE_HEADERS+=asn_codecs_prim.h
|
||||
ASN_MODULE_HEADERS+=ber_tlv_length.h
|
||||
ASN_MODULE_SOURCES+=ber_tlv_length.c
|
||||
ASN_MODULE_HEADERS+=ber_tlv_tag.h
|
||||
ASN_MODULE_SOURCES+=ber_tlv_tag.c
|
||||
ASN_MODULE_HEADERS+=ber_decoder.h
|
||||
ASN_MODULE_SOURCES+=ber_decoder.c
|
||||
ASN_MODULE_HEADERS+=der_encoder.h
|
||||
ASN_MODULE_SOURCES+=der_encoder.c
|
||||
ASN_MODULE_HEADERS+=constr_TYPE.h
|
||||
ASN_MODULE_SOURCES+=constr_TYPE.c
|
||||
ASN_MODULE_HEADERS+=constraints.h
|
||||
ASN_MODULE_SOURCES+=constraints.c
|
||||
ASN_MODULE_HEADERS+=xer_support.h
|
||||
ASN_MODULE_SOURCES+=xer_support.c
|
||||
ASN_MODULE_HEADERS+=xer_decoder.h
|
||||
ASN_MODULE_SOURCES+=xer_decoder.c
|
||||
ASN_MODULE_HEADERS+=xer_encoder.h
|
||||
ASN_MODULE_SOURCES+=xer_encoder.c
|
||||
ASN_MODULE_HEADERS+=per_support.h
|
||||
ASN_MODULE_SOURCES+=per_support.c
|
||||
ASN_MODULE_HEADERS+=per_decoder.h
|
||||
ASN_MODULE_SOURCES+=per_decoder.c
|
||||
ASN_MODULE_HEADERS+=per_encoder.h
|
||||
ASN_MODULE_SOURCES+=per_encoder.c
|
||||
ASN_MODULE_HEADERS+=per_opentype.h
|
||||
ASN_MODULE_SOURCES+=per_opentype.c
|
||||
ASN_CONVERTER_SOURCES+=converter-sample.c
|
||||
|
||||
|
||||
lib_LTLIBRARIES=libsomething.la
|
||||
libsomething_la_SOURCES=$(ASN_MODULE_SOURCES) $(ASN_MODULE_HEADERS)
|
||||
|
||||
# This file may be used as an input for make(3)
|
||||
# Remove the lines below to convert it into a pure .am file
|
||||
TARGET = progname
|
||||
CFLAGS += -I.
|
||||
OBJS=${ASN_MODULE_SOURCES:.c=.o} ${ASN_CONVERTER_SOURCES:.c=.o}
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): ${OBJS}
|
||||
$(CC) $(CFLAGS) -o $(TARGET) ${OBJS} $(LDFLAGS) $(LIBS)
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
rm -f $(OBJS)
|
||||
|
||||
regen: regenerate-from-asn1-source
|
||||
|
||||
regenerate-from-asn1-source:
|
||||
asn1c CryptoConditions.asn
|
||||
|
||||
207
src/cryptoconditions/src/asn/NativeEnumerated.c
Normal file
207
src/cryptoconditions/src/asn/NativeEnumerated.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/*-
|
||||
* Copyright (c) 2004, 2007 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
/*
|
||||
* Read the NativeInteger.h for the explanation wrt. differences between
|
||||
* INTEGER and NativeInteger.
|
||||
* Basically, both are decoders and encoders of ASN.1 INTEGER type, but this
|
||||
* implementation deals with the standard (machine-specific) representation
|
||||
* of them instead of using the platform-independent buffer.
|
||||
*/
|
||||
#include <asn_internal.h>
|
||||
#include <NativeEnumerated.h>
|
||||
|
||||
/*
|
||||
* NativeEnumerated basic type description.
|
||||
*/
|
||||
static const ber_tlv_tag_t asn_DEF_NativeEnumerated_tags[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (10 << 2))
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = {
|
||||
"ENUMERATED", /* The ASN.1 type is still ENUMERATED */
|
||||
"ENUMERATED",
|
||||
NativeInteger_free,
|
||||
NativeInteger_print,
|
||||
asn_generic_no_constraint,
|
||||
NativeInteger_decode_ber,
|
||||
NativeInteger_encode_der,
|
||||
NativeInteger_decode_xer,
|
||||
NativeEnumerated_encode_xer,
|
||||
NativeEnumerated_decode_uper,
|
||||
NativeEnumerated_encode_uper,
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_NativeEnumerated_tags,
|
||||
sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]),
|
||||
asn_DEF_NativeEnumerated_tags, /* Same as above */
|
||||
sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]),
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
0 /* No specifics */
|
||||
};
|
||||
|
||||
asn_enc_rval_t
|
||||
NativeEnumerated_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
asn_enc_rval_t er;
|
||||
const long *native = (const long *)sptr;
|
||||
const asn_INTEGER_enum_map_t *el;
|
||||
|
||||
(void)ilevel;
|
||||
(void)flags;
|
||||
|
||||
if(!native) ASN__ENCODE_FAILED;
|
||||
|
||||
el = INTEGER_map_value2enum(specs, *native);
|
||||
if(el) {
|
||||
size_t srcsize = el->enum_len + 5;
|
||||
char *src = (char *)alloca(srcsize);
|
||||
|
||||
er.encoded = snprintf(src, srcsize, "<%s/>", el->enum_name);
|
||||
assert(er.encoded > 0 && (size_t)er.encoded < srcsize);
|
||||
if(cb(src, er.encoded, app_key) < 0) ASN__ENCODE_FAILED;
|
||||
ASN__ENCODED_OK(er);
|
||||
} else {
|
||||
ASN_DEBUG("ASN.1 forbids dealing with "
|
||||
"unknown value of ENUMERATED type");
|
||||
ASN__ENCODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
asn_dec_rval_t
|
||||
NativeEnumerated_decode_uper(asn_codec_ctx_t *opt_codec_ctx,
|
||||
asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
|
||||
void **sptr, asn_per_data_t *pd) {
|
||||
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
|
||||
asn_dec_rval_t rval = { RC_OK, 0 };
|
||||
long *native = (long *)*sptr;
|
||||
asn_per_constraint_t *ct;
|
||||
long value;
|
||||
|
||||
(void)opt_codec_ctx;
|
||||
|
||||
if(constraints) ct = &constraints->value;
|
||||
else if(td->per_constraints) ct = &td->per_constraints->value;
|
||||
else ASN__DECODE_FAILED; /* Mandatory! */
|
||||
if(!specs) ASN__DECODE_FAILED;
|
||||
|
||||
if(!native) {
|
||||
native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
|
||||
if(!native) ASN__DECODE_FAILED;
|
||||
}
|
||||
|
||||
ASN_DEBUG("Decoding %s as NativeEnumerated", td->name);
|
||||
|
||||
if(ct->flags & APC_EXTENSIBLE) {
|
||||
int inext = per_get_few_bits(pd, 1);
|
||||
if(inext < 0) ASN__DECODE_STARVED;
|
||||
if(inext) ct = 0;
|
||||
}
|
||||
|
||||
if(ct && ct->range_bits >= 0) {
|
||||
value = per_get_few_bits(pd, ct->range_bits);
|
||||
if(value < 0) ASN__DECODE_STARVED;
|
||||
if(value >= (specs->extension
|
||||
? specs->extension - 1 : specs->map_count))
|
||||
ASN__DECODE_FAILED;
|
||||
} else {
|
||||
if(!specs->extension)
|
||||
ASN__DECODE_FAILED;
|
||||
/*
|
||||
* X.691, #10.6: normally small non-negative whole number;
|
||||
*/
|
||||
value = uper_get_nsnnwn(pd);
|
||||
if(value < 0) ASN__DECODE_STARVED;
|
||||
value += specs->extension - 1;
|
||||
if(value >= specs->map_count)
|
||||
ASN__DECODE_FAILED;
|
||||
}
|
||||
|
||||
*native = specs->value2enum[value].nat_value;
|
||||
ASN_DEBUG("Decoded %s = %ld", td->name, *native);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
static int
|
||||
NativeEnumerated__compar_value2enum(const void *ap, const void *bp) {
|
||||
const asn_INTEGER_enum_map_t *a = ap;
|
||||
const asn_INTEGER_enum_map_t *b = bp;
|
||||
if(a->nat_value == b->nat_value)
|
||||
return 0;
|
||||
if(a->nat_value < b->nat_value)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
asn_enc_rval_t
|
||||
NativeEnumerated_encode_uper(asn_TYPE_descriptor_t *td,
|
||||
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
|
||||
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
|
||||
asn_enc_rval_t er;
|
||||
long native, value;
|
||||
asn_per_constraint_t *ct;
|
||||
int inext = 0;
|
||||
asn_INTEGER_enum_map_t key;
|
||||
const asn_INTEGER_enum_map_t *kf;
|
||||
|
||||
if(!sptr) ASN__ENCODE_FAILED;
|
||||
if(!specs) ASN__ENCODE_FAILED;
|
||||
|
||||
if(constraints) ct = &constraints->value;
|
||||
else if(td->per_constraints) ct = &td->per_constraints->value;
|
||||
else ASN__ENCODE_FAILED; /* Mandatory! */
|
||||
|
||||
ASN_DEBUG("Encoding %s as NativeEnumerated", td->name);
|
||||
|
||||
er.encoded = 0;
|
||||
|
||||
native = *(long *)sptr;
|
||||
if(native < 0) ASN__ENCODE_FAILED;
|
||||
|
||||
key.nat_value = native;
|
||||
kf = bsearch(&key, specs->value2enum, specs->map_count,
|
||||
sizeof(key), NativeEnumerated__compar_value2enum);
|
||||
if(!kf) {
|
||||
ASN_DEBUG("No element corresponds to %ld", native);
|
||||
ASN__ENCODE_FAILED;
|
||||
}
|
||||
value = kf - specs->value2enum;
|
||||
|
||||
if(ct->range_bits >= 0) {
|
||||
int cmpWith = specs->extension
|
||||
? specs->extension - 1 : specs->map_count;
|
||||
if(value >= cmpWith)
|
||||
inext = 1;
|
||||
}
|
||||
if(ct->flags & APC_EXTENSIBLE) {
|
||||
if(per_put_few_bits(po, inext, 1))
|
||||
ASN__ENCODE_FAILED;
|
||||
if(inext) ct = 0;
|
||||
} else if(inext) {
|
||||
ASN__ENCODE_FAILED;
|
||||
}
|
||||
|
||||
if(ct && ct->range_bits >= 0) {
|
||||
if(per_put_few_bits(po, value, ct->range_bits))
|
||||
ASN__ENCODE_FAILED;
|
||||
ASN__ENCODED_OK(er);
|
||||
}
|
||||
|
||||
if(!specs->extension)
|
||||
ASN__ENCODE_FAILED;
|
||||
|
||||
/*
|
||||
* X.691, #10.6: normally small non-negative whole number;
|
||||
*/
|
||||
ASN_DEBUG("value = %ld, ext = %d, inext = %d, res = %ld",
|
||||
value, specs->extension, inext,
|
||||
value - (inext ? (specs->extension - 1) : 0));
|
||||
if(uper_put_nsnnwn(po, value - (inext ? (specs->extension - 1) : 0)))
|
||||
ASN__ENCODE_FAILED;
|
||||
|
||||
ASN__ENCODED_OK(er);
|
||||
}
|
||||
|
||||
32
src/cryptoconditions/src/asn/NativeEnumerated.h
Normal file
32
src/cryptoconditions/src/asn/NativeEnumerated.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*-
|
||||
* Copyright (c) 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>.
|
||||
* All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
/*
|
||||
* This type differs from the standard ENUMERATED in that it is modelled using
|
||||
* the fixed machine type (long, int, short), so it can hold only values of
|
||||
* limited length. There is no type (i.e., NativeEnumerated_t, any integer type
|
||||
* will do).
|
||||
* This type may be used when integer range is limited by subtype constraints.
|
||||
*/
|
||||
#ifndef _NativeEnumerated_H_
|
||||
#define _NativeEnumerated_H_
|
||||
|
||||
#include <NativeInteger.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_NativeEnumerated;
|
||||
|
||||
xer_type_encoder_f NativeEnumerated_encode_xer;
|
||||
per_type_decoder_f NativeEnumerated_decode_uper;
|
||||
per_type_encoder_f NativeEnumerated_encode_uper;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _NativeEnumerated_H_ */
|
||||
332
src/cryptoconditions/src/asn/NativeInteger.c
Normal file
332
src/cryptoconditions/src/asn/NativeInteger.c
Normal file
@@ -0,0 +1,332 @@
|
||||
/*-
|
||||
* Copyright (c) 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>.
|
||||
* All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
/*
|
||||
* Read the NativeInteger.h for the explanation wrt. differences between
|
||||
* INTEGER and NativeInteger.
|
||||
* Basically, both are decoders and encoders of ASN.1 INTEGER type, but this
|
||||
* implementation deals with the standard (machine-specific) representation
|
||||
* of them instead of using the platform-independent buffer.
|
||||
*/
|
||||
#include <asn_internal.h>
|
||||
#include <NativeInteger.h>
|
||||
|
||||
/*
|
||||
* NativeInteger basic type description.
|
||||
*/
|
||||
static const ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_NativeInteger = {
|
||||
"INTEGER", /* The ASN.1 type is still INTEGER */
|
||||
"INTEGER",
|
||||
NativeInteger_free,
|
||||
NativeInteger_print,
|
||||
asn_generic_no_constraint,
|
||||
NativeInteger_decode_ber,
|
||||
NativeInteger_encode_der,
|
||||
NativeInteger_decode_xer,
|
||||
NativeInteger_encode_xer,
|
||||
NativeInteger_decode_uper, /* Unaligned PER decoder */
|
||||
NativeInteger_encode_uper, /* Unaligned PER encoder */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_NativeInteger_tags,
|
||||
sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]),
|
||||
asn_DEF_NativeInteger_tags, /* Same as above */
|
||||
sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]),
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
0 /* No specifics */
|
||||
};
|
||||
|
||||
/*
|
||||
* Decode INTEGER type.
|
||||
*/
|
||||
asn_dec_rval_t
|
||||
NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
|
||||
asn_TYPE_descriptor_t *td,
|
||||
void **nint_ptr, const void *buf_ptr, size_t size, int tag_mode) {
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
long *native = (long *)*nint_ptr;
|
||||
asn_dec_rval_t rval;
|
||||
ber_tlv_len_t length;
|
||||
|
||||
/*
|
||||
* If the structure is not there, allocate it.
|
||||
*/
|
||||
if(native == NULL) {
|
||||
native = (long *)(*nint_ptr = CALLOC(1, sizeof(*native)));
|
||||
if(native == NULL) {
|
||||
rval.code = RC_FAIL;
|
||||
rval.consumed = 0;
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
|
||||
ASN_DEBUG("Decoding %s as INTEGER (tm=%d)",
|
||||
td->name, tag_mode);
|
||||
|
||||
/*
|
||||
* Check tags.
|
||||
*/
|
||||
rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size,
|
||||
tag_mode, 0, &length, 0);
|
||||
if(rval.code != RC_OK)
|
||||
return rval;
|
||||
|
||||
ASN_DEBUG("%s length is %d bytes", td->name, (int)length);
|
||||
|
||||
/*
|
||||
* Make sure we have this length.
|
||||
*/
|
||||
buf_ptr = ((const char *)buf_ptr) + rval.consumed;
|
||||
size -= rval.consumed;
|
||||
if(length > (ber_tlv_len_t)size) {
|
||||
rval.code = RC_WMORE;
|
||||
rval.consumed = 0;
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
* ASN.1 encoded INTEGER: buf_ptr, length
|
||||
* Fill the native, at the same time checking for overflow.
|
||||
* If overflow occured, return with RC_FAIL.
|
||||
*/
|
||||
{
|
||||
INTEGER_t tmp;
|
||||
union {
|
||||
const void *constbuf;
|
||||
void *nonconstbuf;
|
||||
} unconst_buf;
|
||||
long l;
|
||||
|
||||
unconst_buf.constbuf = buf_ptr;
|
||||
tmp.buf = (uint8_t *)unconst_buf.nonconstbuf;
|
||||
tmp.size = length;
|
||||
|
||||
if((specs&&specs->field_unsigned)
|
||||
? asn_INTEGER2ulong(&tmp, (unsigned long *)&l) /* sic */
|
||||
: asn_INTEGER2long(&tmp, &l)) {
|
||||
rval.code = RC_FAIL;
|
||||
rval.consumed = 0;
|
||||
return rval;
|
||||
}
|
||||
|
||||
*native = l;
|
||||
}
|
||||
|
||||
rval.code = RC_OK;
|
||||
rval.consumed += length;
|
||||
|
||||
ASN_DEBUG("Took %ld/%ld bytes to encode %s (%ld)",
|
||||
(long)rval.consumed, (long)length, td->name, (long)*native);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode the NativeInteger using the standard INTEGER type DER encoder.
|
||||
*/
|
||||
asn_enc_rval_t
|
||||
NativeInteger_encode_der(asn_TYPE_descriptor_t *sd, void *ptr,
|
||||
int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
unsigned long native = *(unsigned long *)ptr; /* Disable sign ext. */
|
||||
asn_enc_rval_t erval;
|
||||
INTEGER_t tmp;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN /* Opportunistic optimization */
|
||||
|
||||
tmp.buf = (uint8_t *)&native;
|
||||
tmp.size = sizeof(native);
|
||||
|
||||
#else /* Works even if WORDS_BIGENDIAN is not set where should've been */
|
||||
uint8_t buf[sizeof(native)];
|
||||
uint8_t *p;
|
||||
|
||||
/* Prepare a fake INTEGER */
|
||||
for(p = buf + sizeof(buf) - 1; p >= buf; p--, native >>= 8)
|
||||
*p = (uint8_t)native;
|
||||
|
||||
tmp.buf = buf;
|
||||
tmp.size = sizeof(buf);
|
||||
#endif /* WORDS_BIGENDIAN */
|
||||
|
||||
/* Encode fake INTEGER */
|
||||
erval = INTEGER_encode_der(sd, &tmp, tag_mode, tag, cb, app_key);
|
||||
if(erval.encoded == -1) {
|
||||
assert(erval.structure_ptr == &tmp);
|
||||
erval.structure_ptr = ptr;
|
||||
}
|
||||
return erval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode the chunk of XML text encoding INTEGER.
|
||||
*/
|
||||
asn_dec_rval_t
|
||||
NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
|
||||
asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
|
||||
const void *buf_ptr, size_t size) {
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
asn_dec_rval_t rval;
|
||||
INTEGER_t st;
|
||||
void *st_ptr = (void *)&st;
|
||||
long *native = (long *)*sptr;
|
||||
|
||||
if(!native) {
|
||||
native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
|
||||
if(!native) ASN__DECODE_FAILED;
|
||||
}
|
||||
|
||||
memset(&st, 0, sizeof(st));
|
||||
rval = INTEGER_decode_xer(opt_codec_ctx, td, &st_ptr,
|
||||
opt_mname, buf_ptr, size);
|
||||
if(rval.code == RC_OK) {
|
||||
long l;
|
||||
if((specs&&specs->field_unsigned)
|
||||
? asn_INTEGER2ulong(&st, (unsigned long *)&l) /* sic */
|
||||
: asn_INTEGER2long(&st, &l)) {
|
||||
rval.code = RC_FAIL;
|
||||
rval.consumed = 0;
|
||||
} else {
|
||||
*native = l;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Cannot restart from the middle;
|
||||
* there is no place to save state in the native type.
|
||||
* Request a continuation from the very beginning.
|
||||
*/
|
||||
rval.consumed = 0;
|
||||
}
|
||||
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &st);
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
asn_enc_rval_t
|
||||
NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
char scratch[32]; /* Enough for 64-bit int */
|
||||
asn_enc_rval_t er;
|
||||
const long *native = (const long *)sptr;
|
||||
|
||||
(void)ilevel;
|
||||
(void)flags;
|
||||
|
||||
if(!native) ASN__ENCODE_FAILED;
|
||||
|
||||
er.encoded = snprintf(scratch, sizeof(scratch),
|
||||
(specs && specs->field_unsigned)
|
||||
? "%lu" : "%ld", *native);
|
||||
if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
|
||||
|| cb(scratch, er.encoded, app_key) < 0)
|
||||
ASN__ENCODE_FAILED;
|
||||
|
||||
ASN__ENCODED_OK(er);
|
||||
}
|
||||
|
||||
asn_dec_rval_t
|
||||
NativeInteger_decode_uper(asn_codec_ctx_t *opt_codec_ctx,
|
||||
asn_TYPE_descriptor_t *td,
|
||||
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
|
||||
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
asn_dec_rval_t rval;
|
||||
long *native = (long *)*sptr;
|
||||
INTEGER_t tmpint;
|
||||
void *tmpintptr = &tmpint;
|
||||
|
||||
(void)opt_codec_ctx;
|
||||
ASN_DEBUG("Decoding NativeInteger %s (UPER)", td->name);
|
||||
|
||||
if(!native) {
|
||||
native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
|
||||
if(!native) ASN__DECODE_FAILED;
|
||||
}
|
||||
|
||||
memset(&tmpint, 0, sizeof tmpint);
|
||||
rval = INTEGER_decode_uper(opt_codec_ctx, td, constraints,
|
||||
&tmpintptr, pd);
|
||||
if(rval.code == RC_OK) {
|
||||
if((specs&&specs->field_unsigned)
|
||||
? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
|
||||
: asn_INTEGER2long(&tmpint, native))
|
||||
rval.code = RC_FAIL;
|
||||
else
|
||||
ASN_DEBUG("NativeInteger %s got value %ld",
|
||||
td->name, *native);
|
||||
}
|
||||
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
asn_enc_rval_t
|
||||
NativeInteger_encode_uper(asn_TYPE_descriptor_t *td,
|
||||
asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
asn_enc_rval_t er;
|
||||
long native;
|
||||
INTEGER_t tmpint;
|
||||
|
||||
if(!sptr) ASN__ENCODE_FAILED;
|
||||
|
||||
native = *(long *)sptr;
|
||||
|
||||
ASN_DEBUG("Encoding NativeInteger %s %ld (UPER)", td->name, native);
|
||||
|
||||
memset(&tmpint, 0, sizeof(tmpint));
|
||||
if((specs&&specs->field_unsigned)
|
||||
? asn_ulong2INTEGER(&tmpint, native)
|
||||
: asn_long2INTEGER(&tmpint, native))
|
||||
ASN__ENCODE_FAILED;
|
||||
er = INTEGER_encode_uper(td, constraints, &tmpint, po);
|
||||
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
|
||||
return er;
|
||||
}
|
||||
|
||||
/*
|
||||
* INTEGER specific human-readable output.
|
||||
*/
|
||||
int
|
||||
NativeInteger_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
|
||||
const long *native = (const long *)sptr;
|
||||
char scratch[32]; /* Enough for 64-bit int */
|
||||
int ret;
|
||||
|
||||
(void)td; /* Unused argument */
|
||||
(void)ilevel; /* Unused argument */
|
||||
|
||||
if(native) {
|
||||
ret = snprintf(scratch, sizeof(scratch),
|
||||
(specs && specs->field_unsigned)
|
||||
? "%lu" : "%ld", *native);
|
||||
assert(ret > 0 && (size_t)ret < sizeof(scratch));
|
||||
return (cb(scratch, ret, app_key) < 0) ? -1 : 0;
|
||||
} else {
|
||||
return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NativeInteger_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
|
||||
|
||||
if(!td || !ptr)
|
||||
return;
|
||||
|
||||
ASN_DEBUG("Freeing %s as INTEGER (%d, %p, Native)",
|
||||
td->name, contents_only, ptr);
|
||||
|
||||
if(!contents_only) {
|
||||
FREEMEM(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
37
src/cryptoconditions/src/asn/NativeInteger.h
Normal file
37
src/cryptoconditions/src/asn/NativeInteger.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
/*
|
||||
* This type differs from the standard INTEGER in that it is modelled using
|
||||
* the fixed machine type (long, int, short), so it can hold only values of
|
||||
* limited length. There is no type (i.e., NativeInteger_t, any integer type
|
||||
* will do).
|
||||
* This type may be used when integer range is limited by subtype constraints.
|
||||
*/
|
||||
#ifndef _NativeInteger_H_
|
||||
#define _NativeInteger_H_
|
||||
|
||||
#include <asn_application.h>
|
||||
#include <INTEGER.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_NativeInteger;
|
||||
|
||||
asn_struct_free_f NativeInteger_free;
|
||||
asn_struct_print_f NativeInteger_print;
|
||||
ber_type_decoder_f NativeInteger_decode_ber;
|
||||
der_type_encoder_f NativeInteger_encode_der;
|
||||
xer_type_decoder_f NativeInteger_decode_xer;
|
||||
xer_type_encoder_f NativeInteger_encode_xer;
|
||||
per_type_decoder_f NativeInteger_decode_uper;
|
||||
per_type_encoder_f NativeInteger_encode_uper;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _NativeInteger_H_ */
|
||||
1807
src/cryptoconditions/src/asn/OCTET_STRING.c
Normal file
1807
src/cryptoconditions/src/asn/OCTET_STRING.c
Normal file
File diff suppressed because it is too large
Load Diff
86
src/cryptoconditions/src/asn/OCTET_STRING.h
Normal file
86
src/cryptoconditions/src/asn/OCTET_STRING.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*-
|
||||
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
||||
* Redistribution and modifications are permitted subject to BSD license.
|
||||
*/
|
||||
#ifndef _OCTET_STRING_H_
|
||||
#define _OCTET_STRING_H_
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct OCTET_STRING {
|
||||
uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
|
||||
int size; /* Size of the buffer */
|
||||
|
||||
asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
|
||||
} OCTET_STRING_t;
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
|
||||
|
||||
asn_struct_free_f OCTET_STRING_free;
|
||||
asn_struct_print_f OCTET_STRING_print;
|
||||
asn_struct_print_f OCTET_STRING_print_utf8;
|
||||
ber_type_decoder_f OCTET_STRING_decode_ber;
|
||||
der_type_encoder_f OCTET_STRING_encode_der;
|
||||
xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */
|
||||
xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */
|
||||
xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */
|
||||
xer_type_encoder_f OCTET_STRING_encode_xer;
|
||||
xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
|
||||
per_type_decoder_f OCTET_STRING_decode_uper;
|
||||
per_type_encoder_f OCTET_STRING_encode_uper;
|
||||
|
||||
/******************************
|
||||
* Handy conversion routines. *
|
||||
******************************/
|
||||
|
||||
/*
|
||||
* This function clears the previous value of the OCTET STRING (if any)
|
||||
* and then allocates a new memory with the specified content (str/size).
|
||||
* If size = -1, the size of the original string will be determined
|
||||
* using strlen(str).
|
||||
* If str equals to NULL, the function will silently clear the
|
||||
* current contents of the OCTET STRING.
|
||||
* Returns 0 if it was possible to perform operation, -1 otherwise.
|
||||
*/
|
||||
int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
|
||||
|
||||
/* Handy conversion from the C string into the OCTET STRING. */
|
||||
#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
|
||||
|
||||
/*
|
||||
* Allocate and fill the new OCTET STRING and return a pointer to the newly
|
||||
* allocated object. NULL is permitted in str: the function will just allocate
|
||||
* empty OCTET STRING.
|
||||
*/
|
||||
OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td,
|
||||
const char *str, int size);
|
||||
|
||||
/****************************
|
||||
* Internally useful stuff. *
|
||||
****************************/
|
||||
|
||||
typedef const struct asn_OCTET_STRING_specifics_s {
|
||||
/*
|
||||
* Target structure description.
|
||||
*/
|
||||
int struct_size; /* Size of the structure */
|
||||
int ctx_offset; /* Offset of the asn_struct_ctx_t member */
|
||||
|
||||
enum asn_OS_Subvariant {
|
||||
ASN_OSUBV_ANY, /* The open type (ANY) */
|
||||
ASN_OSUBV_BIT, /* BIT STRING */
|
||||
ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */
|
||||
ASN_OSUBV_U16, /* 16-bit character (BMPString) */
|
||||
ASN_OSUBV_U32 /* 32-bit character (UniversalString) */
|
||||
} subvariant;
|
||||
} asn_OCTET_STRING_specifics_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _OCTET_STRING_H_ */
|
||||
209
src/cryptoconditions/src/asn/PrefixFingerprintContents.c
Normal file
209
src/cryptoconditions/src/asn/PrefixFingerprintContents.c
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "PrefixFingerprintContents.h"
|
||||
|
||||
static int
|
||||
maxMessageLength_3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This type is implemented using NativeInteger,
|
||||
* so here we adjust the DEF accordingly.
|
||||
*/
|
||||
static void
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {
|
||||
td->free_struct = asn_DEF_NativeInteger.free_struct;
|
||||
td->print_struct = asn_DEF_NativeInteger.print_struct;
|
||||
td->check_constraints = asn_DEF_NativeInteger.check_constraints;
|
||||
td->ber_decoder = asn_DEF_NativeInteger.ber_decoder;
|
||||
td->der_encoder = asn_DEF_NativeInteger.der_encoder;
|
||||
td->xer_decoder = asn_DEF_NativeInteger.xer_decoder;
|
||||
td->xer_encoder = asn_DEF_NativeInteger.xer_encoder;
|
||||
td->uper_decoder = asn_DEF_NativeInteger.uper_decoder;
|
||||
td->uper_encoder = asn_DEF_NativeInteger.uper_encoder;
|
||||
if(!td->per_constraints)
|
||||
td->per_constraints = asn_DEF_NativeInteger.per_constraints;
|
||||
td->elements = asn_DEF_NativeInteger.elements;
|
||||
td->elements_count = asn_DEF_NativeInteger.elements_count;
|
||||
/* td->specifics = asn_DEF_NativeInteger.specifics; // Defined explicitly */
|
||||
}
|
||||
|
||||
static void
|
||||
maxMessageLength_3_free(asn_TYPE_descriptor_t *td,
|
||||
void *struct_ptr, int contents_only) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
td->free_struct(td, struct_ptr, contents_only);
|
||||
}
|
||||
|
||||
static int
|
||||
maxMessageLength_3_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,
|
||||
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
maxMessageLength_3_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const void *bufptr, size_t size, int tag_mode) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
maxMessageLength_3_encode_der(asn_TYPE_descriptor_t *td,
|
||||
void *structure, int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
maxMessageLength_3_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const char *opt_mname, const void *bufptr, size_t size) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
maxMessageLength_3_encode_xer(asn_TYPE_descriptor_t *td, void *structure,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
|
||||
}
|
||||
|
||||
static int
|
||||
memb_maxMessageLength_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const asn_INTEGER_specifics_t asn_SPC_maxMessageLength_specs_3 = {
|
||||
0, 0, 0, 0, 0,
|
||||
0, /* Native long size */
|
||||
1 /* Unsigned representation */
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_maxMessageLength_tags_3[] = {
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
|
||||
};
|
||||
static /* Use -fall-defs-global to expose */
|
||||
asn_TYPE_descriptor_t asn_DEF_maxMessageLength_3 = {
|
||||
"maxMessageLength",
|
||||
"maxMessageLength",
|
||||
maxMessageLength_3_free,
|
||||
maxMessageLength_3_print,
|
||||
maxMessageLength_3_constraint,
|
||||
maxMessageLength_3_decode_ber,
|
||||
maxMessageLength_3_encode_der,
|
||||
maxMessageLength_3_decode_xer,
|
||||
maxMessageLength_3_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_maxMessageLength_tags_3,
|
||||
sizeof(asn_DEF_maxMessageLength_tags_3)
|
||||
/sizeof(asn_DEF_maxMessageLength_tags_3[0]) - 1, /* 1 */
|
||||
asn_DEF_maxMessageLength_tags_3, /* Same as above */
|
||||
sizeof(asn_DEF_maxMessageLength_tags_3)
|
||||
/sizeof(asn_DEF_maxMessageLength_tags_3[0]), /* 2 */
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
&asn_SPC_maxMessageLength_specs_3 /* Additional specs */
|
||||
};
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_PrefixFingerprintContents_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct PrefixFingerprintContents, prefix),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"prefix"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct PrefixFingerprintContents, maxMessageLength),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_maxMessageLength_3,
|
||||
memb_maxMessageLength_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"maxMessageLength"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct PrefixFingerprintContents, subcondition),
|
||||
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
|
||||
+1, /* EXPLICIT tag at current level */
|
||||
&asn_DEF_Condition,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"subcondition"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_PrefixFingerprintContents_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_PrefixFingerprintContents_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* prefix */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* maxMessageLength */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* subcondition */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_PrefixFingerprintContents_specs_1 = {
|
||||
sizeof(struct PrefixFingerprintContents),
|
||||
offsetof(struct PrefixFingerprintContents, _asn_ctx),
|
||||
asn_MAP_PrefixFingerprintContents_tag2el_1,
|
||||
3, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_PrefixFingerprintContents = {
|
||||
"PrefixFingerprintContents",
|
||||
"PrefixFingerprintContents",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_PrefixFingerprintContents_tags_1,
|
||||
sizeof(asn_DEF_PrefixFingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_PrefixFingerprintContents_tags_1[0]), /* 1 */
|
||||
asn_DEF_PrefixFingerprintContents_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_PrefixFingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_PrefixFingerprintContents_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_PrefixFingerprintContents_1,
|
||||
3, /* Elements count */
|
||||
&asn_SPC_PrefixFingerprintContents_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
42
src/cryptoconditions/src/asn/PrefixFingerprintContents.h
Normal file
42
src/cryptoconditions/src/asn/PrefixFingerprintContents.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _PrefixFingerprintContents_H_
|
||||
#define _PrefixFingerprintContents_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <NativeInteger.h>
|
||||
#include "Condition.h"
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* PrefixFingerprintContents */
|
||||
typedef struct PrefixFingerprintContents {
|
||||
OCTET_STRING_t prefix;
|
||||
unsigned long maxMessageLength;
|
||||
Condition_t subcondition;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} PrefixFingerprintContents_t;
|
||||
|
||||
/* Implementation */
|
||||
/* extern asn_TYPE_descriptor_t asn_DEF_maxMessageLength_3; // (Use -fall-defs-global to expose) */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_PrefixFingerprintContents;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _PrefixFingerprintContents_H_ */
|
||||
#include <asn_internal.h>
|
||||
209
src/cryptoconditions/src/asn/PrefixFulfillment.c
Normal file
209
src/cryptoconditions/src/asn/PrefixFulfillment.c
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "PrefixFulfillment.h"
|
||||
|
||||
static int
|
||||
maxMessageLength_3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This type is implemented using NativeInteger,
|
||||
* so here we adjust the DEF accordingly.
|
||||
*/
|
||||
static void
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {
|
||||
td->free_struct = asn_DEF_NativeInteger.free_struct;
|
||||
td->print_struct = asn_DEF_NativeInteger.print_struct;
|
||||
td->check_constraints = asn_DEF_NativeInteger.check_constraints;
|
||||
td->ber_decoder = asn_DEF_NativeInteger.ber_decoder;
|
||||
td->der_encoder = asn_DEF_NativeInteger.der_encoder;
|
||||
td->xer_decoder = asn_DEF_NativeInteger.xer_decoder;
|
||||
td->xer_encoder = asn_DEF_NativeInteger.xer_encoder;
|
||||
td->uper_decoder = asn_DEF_NativeInteger.uper_decoder;
|
||||
td->uper_encoder = asn_DEF_NativeInteger.uper_encoder;
|
||||
if(!td->per_constraints)
|
||||
td->per_constraints = asn_DEF_NativeInteger.per_constraints;
|
||||
td->elements = asn_DEF_NativeInteger.elements;
|
||||
td->elements_count = asn_DEF_NativeInteger.elements_count;
|
||||
/* td->specifics = asn_DEF_NativeInteger.specifics; // Defined explicitly */
|
||||
}
|
||||
|
||||
static void
|
||||
maxMessageLength_3_free(asn_TYPE_descriptor_t *td,
|
||||
void *struct_ptr, int contents_only) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
td->free_struct(td, struct_ptr, contents_only);
|
||||
}
|
||||
|
||||
static int
|
||||
maxMessageLength_3_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,
|
||||
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
maxMessageLength_3_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const void *bufptr, size_t size, int tag_mode) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
maxMessageLength_3_encode_der(asn_TYPE_descriptor_t *td,
|
||||
void *structure, int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
maxMessageLength_3_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const char *opt_mname, const void *bufptr, size_t size) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
maxMessageLength_3_encode_xer(asn_TYPE_descriptor_t *td, void *structure,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
maxMessageLength_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
|
||||
}
|
||||
|
||||
static int
|
||||
memb_maxMessageLength_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const asn_INTEGER_specifics_t asn_SPC_maxMessageLength_specs_3 = {
|
||||
0, 0, 0, 0, 0,
|
||||
0, /* Native long size */
|
||||
1 /* Unsigned representation */
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_maxMessageLength_tags_3[] = {
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
|
||||
};
|
||||
static /* Use -fall-defs-global to expose */
|
||||
asn_TYPE_descriptor_t asn_DEF_maxMessageLength_3 = {
|
||||
"maxMessageLength",
|
||||
"maxMessageLength",
|
||||
maxMessageLength_3_free,
|
||||
maxMessageLength_3_print,
|
||||
maxMessageLength_3_constraint,
|
||||
maxMessageLength_3_decode_ber,
|
||||
maxMessageLength_3_encode_der,
|
||||
maxMessageLength_3_decode_xer,
|
||||
maxMessageLength_3_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_maxMessageLength_tags_3,
|
||||
sizeof(asn_DEF_maxMessageLength_tags_3)
|
||||
/sizeof(asn_DEF_maxMessageLength_tags_3[0]) - 1, /* 1 */
|
||||
asn_DEF_maxMessageLength_tags_3, /* Same as above */
|
||||
sizeof(asn_DEF_maxMessageLength_tags_3)
|
||||
/sizeof(asn_DEF_maxMessageLength_tags_3[0]), /* 2 */
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
&asn_SPC_maxMessageLength_specs_3 /* Additional specs */
|
||||
};
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_PrefixFulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct PrefixFulfillment, prefix),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"prefix"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct PrefixFulfillment, maxMessageLength),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_maxMessageLength_3,
|
||||
memb_maxMessageLength_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"maxMessageLength"
|
||||
},
|
||||
{ ATF_POINTER, 0, offsetof(struct PrefixFulfillment, subfulfillment),
|
||||
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
|
||||
+1, /* EXPLICIT tag at current level */
|
||||
&asn_DEF_Fulfillment,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"subfulfillment"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_PrefixFulfillment_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_PrefixFulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* prefix */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* maxMessageLength */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* subfulfillment */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_PrefixFulfillment_specs_1 = {
|
||||
sizeof(struct PrefixFulfillment),
|
||||
offsetof(struct PrefixFulfillment, _asn_ctx),
|
||||
asn_MAP_PrefixFulfillment_tag2el_1,
|
||||
3, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_PrefixFulfillment = {
|
||||
"PrefixFulfillment",
|
||||
"PrefixFulfillment",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_PrefixFulfillment_tags_1,
|
||||
sizeof(asn_DEF_PrefixFulfillment_tags_1)
|
||||
/sizeof(asn_DEF_PrefixFulfillment_tags_1[0]), /* 1 */
|
||||
asn_DEF_PrefixFulfillment_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_PrefixFulfillment_tags_1)
|
||||
/sizeof(asn_DEF_PrefixFulfillment_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_PrefixFulfillment_1,
|
||||
3, /* Elements count */
|
||||
&asn_SPC_PrefixFulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
47
src/cryptoconditions/src/asn/PrefixFulfillment.h
Normal file
47
src/cryptoconditions/src/asn/PrefixFulfillment.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _PrefixFulfillment_H_
|
||||
#define _PrefixFulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <NativeInteger.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Forward declarations */
|
||||
struct Fulfillment;
|
||||
|
||||
/* PrefixFulfillment */
|
||||
typedef struct PrefixFulfillment {
|
||||
OCTET_STRING_t prefix;
|
||||
unsigned long maxMessageLength;
|
||||
struct Fulfillment *subfulfillment;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} PrefixFulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
/* extern asn_TYPE_descriptor_t asn_DEF_maxMessageLength_3; // (Use -fall-defs-global to expose) */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_PrefixFulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Referred external types */
|
||||
#include "Fulfillment.h"
|
||||
|
||||
#endif /* _PrefixFulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
58
src/cryptoconditions/src/asn/PreimageFulfillment.c
Normal file
58
src/cryptoconditions/src/asn/PreimageFulfillment.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "PreimageFulfillment.h"
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_PreimageFulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct PreimageFulfillment, preimage),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"preimage"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_PreimageFulfillment_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_PreimageFulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* preimage */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_PreimageFulfillment_specs_1 = {
|
||||
sizeof(struct PreimageFulfillment),
|
||||
offsetof(struct PreimageFulfillment, _asn_ctx),
|
||||
asn_MAP_PreimageFulfillment_tag2el_1,
|
||||
1, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_PreimageFulfillment = {
|
||||
"PreimageFulfillment",
|
||||
"PreimageFulfillment",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_PreimageFulfillment_tags_1,
|
||||
sizeof(asn_DEF_PreimageFulfillment_tags_1)
|
||||
/sizeof(asn_DEF_PreimageFulfillment_tags_1[0]), /* 1 */
|
||||
asn_DEF_PreimageFulfillment_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_PreimageFulfillment_tags_1)
|
||||
/sizeof(asn_DEF_PreimageFulfillment_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_PreimageFulfillment_1,
|
||||
1, /* Elements count */
|
||||
&asn_SPC_PreimageFulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
37
src/cryptoconditions/src/asn/PreimageFulfillment.h
Normal file
37
src/cryptoconditions/src/asn/PreimageFulfillment.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _PreimageFulfillment_H_
|
||||
#define _PreimageFulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* PreimageFulfillment */
|
||||
typedef struct PreimageFulfillment {
|
||||
OCTET_STRING_t preimage;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} PreimageFulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_PreimageFulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _PreimageFulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
58
src/cryptoconditions/src/asn/RsaFingerprintContents.c
Normal file
58
src/cryptoconditions/src/asn/RsaFingerprintContents.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "RsaFingerprintContents.h"
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_RsaFingerprintContents_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct RsaFingerprintContents, modulus),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"modulus"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_RsaFingerprintContents_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_RsaFingerprintContents_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* modulus */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_RsaFingerprintContents_specs_1 = {
|
||||
sizeof(struct RsaFingerprintContents),
|
||||
offsetof(struct RsaFingerprintContents, _asn_ctx),
|
||||
asn_MAP_RsaFingerprintContents_tag2el_1,
|
||||
1, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_RsaFingerprintContents = {
|
||||
"RsaFingerprintContents",
|
||||
"RsaFingerprintContents",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_RsaFingerprintContents_tags_1,
|
||||
sizeof(asn_DEF_RsaFingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_RsaFingerprintContents_tags_1[0]), /* 1 */
|
||||
asn_DEF_RsaFingerprintContents_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_RsaFingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_RsaFingerprintContents_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_RsaFingerprintContents_1,
|
||||
1, /* Elements count */
|
||||
&asn_SPC_RsaFingerprintContents_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
37
src/cryptoconditions/src/asn/RsaFingerprintContents.h
Normal file
37
src/cryptoconditions/src/asn/RsaFingerprintContents.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _RsaFingerprintContents_H_
|
||||
#define _RsaFingerprintContents_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* RsaFingerprintContents */
|
||||
typedef struct RsaFingerprintContents {
|
||||
OCTET_STRING_t modulus;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} RsaFingerprintContents_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_RsaFingerprintContents;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RsaFingerprintContents_H_ */
|
||||
#include <asn_internal.h>
|
||||
68
src/cryptoconditions/src/asn/RsaSha256Fulfillment.c
Normal file
68
src/cryptoconditions/src/asn/RsaSha256Fulfillment.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "RsaSha256Fulfillment.h"
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_RsaSha256Fulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct RsaSha256Fulfillment, modulus),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"modulus"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct RsaSha256Fulfillment, signature),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
0, /* Defer constraints checking to the member type */
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"signature"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_RsaSha256Fulfillment_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_RsaSha256Fulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* modulus */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* signature */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_RsaSha256Fulfillment_specs_1 = {
|
||||
sizeof(struct RsaSha256Fulfillment),
|
||||
offsetof(struct RsaSha256Fulfillment, _asn_ctx),
|
||||
asn_MAP_RsaSha256Fulfillment_tag2el_1,
|
||||
2, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_RsaSha256Fulfillment = {
|
||||
"RsaSha256Fulfillment",
|
||||
"RsaSha256Fulfillment",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_RsaSha256Fulfillment_tags_1,
|
||||
sizeof(asn_DEF_RsaSha256Fulfillment_tags_1)
|
||||
/sizeof(asn_DEF_RsaSha256Fulfillment_tags_1[0]), /* 1 */
|
||||
asn_DEF_RsaSha256Fulfillment_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_RsaSha256Fulfillment_tags_1)
|
||||
/sizeof(asn_DEF_RsaSha256Fulfillment_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_RsaSha256Fulfillment_1,
|
||||
2, /* Elements count */
|
||||
&asn_SPC_RsaSha256Fulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
38
src/cryptoconditions/src/asn/RsaSha256Fulfillment.h
Normal file
38
src/cryptoconditions/src/asn/RsaSha256Fulfillment.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _RsaSha256Fulfillment_H_
|
||||
#define _RsaSha256Fulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* RsaSha256Fulfillment */
|
||||
typedef struct RsaSha256Fulfillment {
|
||||
OCTET_STRING_t modulus;
|
||||
OCTET_STRING_t signature;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} RsaSha256Fulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_RsaSha256Fulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RsaSha256Fulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
84
src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c
Normal file
84
src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "Secp256k1FingerprintContents.h"
|
||||
|
||||
static int
|
||||
memb_publicKey_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 33)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_Secp256k1FingerprintContents_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Secp256k1FingerprintContents, publicKey),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_publicKey_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"publicKey"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_Secp256k1FingerprintContents_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_Secp256k1FingerprintContents_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* publicKey */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_Secp256k1FingerprintContents_specs_1 = {
|
||||
sizeof(struct Secp256k1FingerprintContents),
|
||||
offsetof(struct Secp256k1FingerprintContents, _asn_ctx),
|
||||
asn_MAP_Secp256k1FingerprintContents_tag2el_1,
|
||||
1, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_Secp256k1FingerprintContents = {
|
||||
"Secp256k1FingerprintContents",
|
||||
"Secp256k1FingerprintContents",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_Secp256k1FingerprintContents_tags_1,
|
||||
sizeof(asn_DEF_Secp256k1FingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_Secp256k1FingerprintContents_tags_1[0]), /* 1 */
|
||||
asn_DEF_Secp256k1FingerprintContents_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_Secp256k1FingerprintContents_tags_1)
|
||||
/sizeof(asn_DEF_Secp256k1FingerprintContents_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_Secp256k1FingerprintContents_1,
|
||||
1, /* Elements count */
|
||||
&asn_SPC_Secp256k1FingerprintContents_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
37
src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h
Normal file
37
src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _Secp256k1FingerprintContents_H_
|
||||
#define _Secp256k1FingerprintContents_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Secp256k1FingerprintContents */
|
||||
typedef struct Secp256k1FingerprintContents {
|
||||
OCTET_STRING_t publicKey;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} Secp256k1FingerprintContents_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_Secp256k1FingerprintContents;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _Secp256k1FingerprintContents_H_ */
|
||||
#include <asn_internal.h>
|
||||
120
src/cryptoconditions/src/asn/Secp256k1Fulfillment.c
Normal file
120
src/cryptoconditions/src/asn/Secp256k1Fulfillment.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "Secp256k1Fulfillment.h"
|
||||
|
||||
static int
|
||||
memb_publicKey_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 33)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memb_signature_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 64)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_Secp256k1Fulfillment_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Secp256k1Fulfillment, publicKey),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_publicKey_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"publicKey"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct Secp256k1Fulfillment, signature),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_signature_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"signature"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_Secp256k1Fulfillment_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_Secp256k1Fulfillment_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* publicKey */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* signature */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_Secp256k1Fulfillment_specs_1 = {
|
||||
sizeof(struct Secp256k1Fulfillment),
|
||||
offsetof(struct Secp256k1Fulfillment, _asn_ctx),
|
||||
asn_MAP_Secp256k1Fulfillment_tag2el_1,
|
||||
2, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_Secp256k1Fulfillment = {
|
||||
"Secp256k1Fulfillment",
|
||||
"Secp256k1Fulfillment",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_Secp256k1Fulfillment_tags_1,
|
||||
sizeof(asn_DEF_Secp256k1Fulfillment_tags_1)
|
||||
/sizeof(asn_DEF_Secp256k1Fulfillment_tags_1[0]), /* 1 */
|
||||
asn_DEF_Secp256k1Fulfillment_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_Secp256k1Fulfillment_tags_1)
|
||||
/sizeof(asn_DEF_Secp256k1Fulfillment_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_Secp256k1Fulfillment_1,
|
||||
2, /* Elements count */
|
||||
&asn_SPC_Secp256k1Fulfillment_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
38
src/cryptoconditions/src/asn/Secp256k1Fulfillment.h
Normal file
38
src/cryptoconditions/src/asn/Secp256k1Fulfillment.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _Secp256k1Fulfillment_H_
|
||||
#define _Secp256k1Fulfillment_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Secp256k1Fulfillment */
|
||||
typedef struct Secp256k1Fulfillment {
|
||||
OCTET_STRING_t publicKey;
|
||||
OCTET_STRING_t signature;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} Secp256k1Fulfillment_t;
|
||||
|
||||
/* Implementation */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_Secp256k1Fulfillment;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _Secp256k1Fulfillment_H_ */
|
||||
#include <asn_internal.h>
|
||||
225
src/cryptoconditions/src/asn/SimpleSha256Condition.c
Normal file
225
src/cryptoconditions/src/asn/SimpleSha256Condition.c
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#include "SimpleSha256Condition.h"
|
||||
|
||||
static int
|
||||
cost_3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This type is implemented using NativeInteger,
|
||||
* so here we adjust the DEF accordingly.
|
||||
*/
|
||||
static void
|
||||
cost_3_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {
|
||||
td->free_struct = asn_DEF_NativeInteger.free_struct;
|
||||
td->print_struct = asn_DEF_NativeInteger.print_struct;
|
||||
td->check_constraints = asn_DEF_NativeInteger.check_constraints;
|
||||
td->ber_decoder = asn_DEF_NativeInteger.ber_decoder;
|
||||
td->der_encoder = asn_DEF_NativeInteger.der_encoder;
|
||||
td->xer_decoder = asn_DEF_NativeInteger.xer_decoder;
|
||||
td->xer_encoder = asn_DEF_NativeInteger.xer_encoder;
|
||||
td->uper_decoder = asn_DEF_NativeInteger.uper_decoder;
|
||||
td->uper_encoder = asn_DEF_NativeInteger.uper_encoder;
|
||||
if(!td->per_constraints)
|
||||
td->per_constraints = asn_DEF_NativeInteger.per_constraints;
|
||||
td->elements = asn_DEF_NativeInteger.elements;
|
||||
td->elements_count = asn_DEF_NativeInteger.elements_count;
|
||||
/* td->specifics = asn_DEF_NativeInteger.specifics; // Defined explicitly */
|
||||
}
|
||||
|
||||
static void
|
||||
cost_3_free(asn_TYPE_descriptor_t *td,
|
||||
void *struct_ptr, int contents_only) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
td->free_struct(td, struct_ptr, contents_only);
|
||||
}
|
||||
|
||||
static int
|
||||
cost_3_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,
|
||||
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
cost_3_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const void *bufptr, size_t size, int tag_mode) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
cost_3_encode_der(asn_TYPE_descriptor_t *td,
|
||||
void *structure, int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
|
||||
}
|
||||
|
||||
static asn_dec_rval_t
|
||||
cost_3_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const char *opt_mname, const void *bufptr, size_t size) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);
|
||||
}
|
||||
|
||||
static asn_enc_rval_t
|
||||
cost_3_encode_xer(asn_TYPE_descriptor_t *td, void *structure,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
cost_3_inherit_TYPE_descriptor(td);
|
||||
return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
|
||||
}
|
||||
|
||||
static int
|
||||
memb_fingerprint_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
|
||||
size_t size;
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = st->size;
|
||||
|
||||
if((size == 32)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memb_cost_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
|
||||
if(!sptr) {
|
||||
ASN__CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const asn_INTEGER_specifics_t asn_SPC_cost_specs_3 = {
|
||||
0, 0, 0, 0, 0,
|
||||
0, /* Native long size */
|
||||
1 /* Unsigned representation */
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_cost_tags_3[] = {
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
|
||||
};
|
||||
static /* Use -fall-defs-global to expose */
|
||||
asn_TYPE_descriptor_t asn_DEF_cost_3 = {
|
||||
"cost",
|
||||
"cost",
|
||||
cost_3_free,
|
||||
cost_3_print,
|
||||
cost_3_constraint,
|
||||
cost_3_decode_ber,
|
||||
cost_3_encode_der,
|
||||
cost_3_decode_xer,
|
||||
cost_3_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_cost_tags_3,
|
||||
sizeof(asn_DEF_cost_tags_3)
|
||||
/sizeof(asn_DEF_cost_tags_3[0]) - 1, /* 1 */
|
||||
asn_DEF_cost_tags_3, /* Same as above */
|
||||
sizeof(asn_DEF_cost_tags_3)
|
||||
/sizeof(asn_DEF_cost_tags_3[0]), /* 2 */
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
&asn_SPC_cost_specs_3 /* Additional specs */
|
||||
};
|
||||
|
||||
static asn_TYPE_member_t asn_MBR_SimpleSha256Condition_1[] = {
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct SimpleSha256Condition, fingerprint),
|
||||
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_OCTET_STRING,
|
||||
memb_fingerprint_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"fingerprint"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct SimpleSha256Condition, cost),
|
||||
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
|
||||
-1, /* IMPLICIT tag at current level */
|
||||
&asn_DEF_cost_3,
|
||||
memb_cost_constraint_1,
|
||||
0, /* PER is not compiled, use -gen-PER */
|
||||
0,
|
||||
"cost"
|
||||
},
|
||||
};
|
||||
static const ber_tlv_tag_t asn_DEF_SimpleSha256Condition_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static const asn_TYPE_tag2member_t asn_MAP_SimpleSha256Condition_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* fingerprint */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* cost */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_SimpleSha256Condition_specs_1 = {
|
||||
sizeof(struct SimpleSha256Condition),
|
||||
offsetof(struct SimpleSha256Condition, _asn_ctx),
|
||||
asn_MAP_SimpleSha256Condition_tag2el_1,
|
||||
2, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_SimpleSha256Condition = {
|
||||
"SimpleSha256Condition",
|
||||
"SimpleSha256Condition",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
0, 0, /* No PER support, use "-gen-PER" to enable */
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_SimpleSha256Condition_tags_1,
|
||||
sizeof(asn_DEF_SimpleSha256Condition_tags_1)
|
||||
/sizeof(asn_DEF_SimpleSha256Condition_tags_1[0]), /* 1 */
|
||||
asn_DEF_SimpleSha256Condition_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_SimpleSha256Condition_tags_1)
|
||||
/sizeof(asn_DEF_SimpleSha256Condition_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_SimpleSha256Condition_1,
|
||||
2, /* Elements count */
|
||||
&asn_SPC_SimpleSha256Condition_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
40
src/cryptoconditions/src/asn/SimpleSha256Condition.h
Normal file
40
src/cryptoconditions/src/asn/SimpleSha256Condition.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
|
||||
* From ASN.1 module "Crypto-Conditions"
|
||||
* found in "CryptoConditions.asn"
|
||||
*/
|
||||
|
||||
#ifndef _SimpleSha256Condition_H_
|
||||
#define _SimpleSha256Condition_H_
|
||||
|
||||
|
||||
#include <asn_application.h>
|
||||
|
||||
/* Including external dependencies */
|
||||
#include <OCTET_STRING.h>
|
||||
#include <NativeInteger.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* SimpleSha256Condition */
|
||||
typedef struct SimpleSha256Condition {
|
||||
OCTET_STRING_t fingerprint;
|
||||
unsigned long cost;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} SimpleSha256Condition_t;
|
||||
|
||||
/* Implementation */
|
||||
/* extern asn_TYPE_descriptor_t asn_DEF_cost_3; // (Use -fall-defs-global to expose) */
|
||||
extern asn_TYPE_descriptor_t asn_DEF_SimpleSha256Condition;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SimpleSha256Condition_H_ */
|
||||
#include <asn_internal.h>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user