Utils
CryptoGroups.Utils.@bin_str
— Macro@bin_str(x)::BitVector
Converts binary representation to BitVector
:
bin"1010" == BitVector([1, 0, 1, 0])
CryptoGroups.Utils.@check
— Macro@check(ex, msg = nothing)
Drop in replacement for @assert
macro as it can be eliminated in optimizations.
CryptoGroups.Utils.@hex_str
— Macro@hex_str(x)::Vector{UInt8}
A convinience macro for converting a hex to byte vector:
hex"AAEF BBEC" == UInt8[0xaa, 0xef, 0xbb, 0xec]
CryptoGroups.Utils.bits2octet
— Methodbits2octet(x::BitVector)::Vector{UInt8}
Converts a bitvector to an octet.
CryptoGroups.Utils.dynamic
— Methoddynamic(x)
Converts static type to it's closest base type. Inverse of static
method.
CryptoGroups.Utils.int2octet
— Methodint2octet(x::Integer, N::Int = bitlength(x))::Vector{UInt8}
Converts integer x
into an octet where optional N
specifies number of allocated bits for the integer encoding.
CryptoGroups.Utils.octet2bits
— Methodoctet2bits(x::Vector{UInt8}[, N::Int])::BitVector
Converts an octet ot a bitvector with an optionally specified length N
.
CryptoGroups.Utils.octet2int
— Methodoctet2int(x::Vector{UInt8})::BigInt
octet2int(x::String)::BigInt
Converts a binary octet to a BigInt
. In case a string is passed it is treated as hexadecimal and is converted with hex2bytes
. Equivalent in represeentation as parse(BigInt, bytes2hex(x), base=16)
.
CryptoGroups.Utils.static
— Methodstatic(x)
static(; kwargs...)
If x
is not bitstype converts to a bitstype representation. Keyword arguments are used to construct a named tuple with every value being converted with static. Can be converted back to original type with dynamic
method.
Example
# Single argument case
x = BigInt(23)
isbitstype(typeof(x)) == false
isbitstype(typeof(static(x))) == true
x == dynamic(static(x))
# NamedTuple construction
nt = static(; x = BigInt(23), y = 51, z = :name)
isbittstype(typeof(nt)) == true
nt.x == BigInt(23) # accessor methods do conversion with dynamic
dynamic(nt) # ordinary named tuple with every value made dynamic