Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Implementations for CIP-121, CIP-122 and CIP-123. Grouped because they all operate on
ByteString
s, and require similar functionality.
Synopsis
- integerToByteString :: Bool -> Integer -> Integer -> BuiltinResult ByteString
- byteStringToInteger :: Bool -> ByteString -> Integer
- andByteString :: Bool -> ByteString -> ByteString -> ByteString
- orByteString :: Bool -> ByteString -> ByteString -> ByteString
- xorByteString :: Bool -> ByteString -> ByteString -> ByteString
- complementByteString :: ByteString -> ByteString
- shiftByteString :: ByteString -> Integer -> ByteString
- rotateByteString :: ByteString -> Integer -> ByteString
- readBit :: ByteString -> Int -> BuiltinResult Bool
- writeBits :: ByteString -> [Integer] -> Bool -> BuiltinResult ByteString
- replicateByte :: Integer -> Word8 -> BuiltinResult ByteString
- countSetBits :: ByteString -> Int
- findFirstSetBit :: ByteString -> Int
- data IntegerToByteStringError
- maximumOutputLength :: Integer
Documentation
integerToByteString :: Bool -> Integer -> Integer -> BuiltinResult ByteString Source #
Wrapper for unsafeIntegerToByteString
to make it more convenient to define as a builtin.
byteStringToInteger :: Bool -> ByteString -> Integer Source #
Conversion from ByteString
to Integer
, as per
CIP-121.
Wrapper for unsafeByteStringToInteger
to make it more convenient to define as a builtin.
andByteString :: Bool -> ByteString -> ByteString -> ByteString Source #
Bitwise logical AND, as per CIP-122.
orByteString :: Bool -> ByteString -> ByteString -> ByteString Source #
Bitwise logical OR, as per CIP-122.
xorByteString :: Bool -> ByteString -> ByteString -> ByteString Source #
Bitwise logical XOR, as per CIP-122.
complementByteString :: ByteString -> ByteString Source #
Bitwise logical complement, as per CIP-122.
shiftByteString :: ByteString -> Integer -> ByteString Source #
Wrapper for calling unsafesShiftByteString
safely. Specifically, we avoid various edge cases:
- Empty
ByteString
s and zero moves don't do anything - Bit moves whose absolute value is larger than the bit length produce all-zeroes
This also ensures we don't accidentally hit integer overflow issues.
rotateByteString :: ByteString -> Integer -> ByteString Source #
Wrapper for calling unsafeRotateByteString
safely. Specifically, we avoid various edge cases:
- Empty
ByteString
s and zero moves don't do anything - Bit moves whose absolute value is larger than the bit length are reduced modulo the length
Furthermore, we can convert all rotations into positive rotations, by noting that a rotation by b
is the same as a rotation by b
, where mod
bitLenbitLen
is the length of the ByteString
argument in bits. This value is always non-negative, and if we get 0, we have nothing to do. This
reduction also helps us avoid integer overflow issues.
readBit :: ByteString -> Int -> BuiltinResult Bool Source #
Bit read at index, as per CIP-122
writeBits :: ByteString -> [Integer] -> Bool -> BuiltinResult ByteString Source #
Bulk bit write, as per CIP-122
replicateByte :: Integer -> Word8 -> BuiltinResult ByteString Source #
Byte replication, as per CIP-122 We want to cautious about the allocation of huge amounts of memory so we impose the same length limit that's used in integerToByteString.
countSetBits :: ByteString -> Int Source #
Counting the number of set bits, as per CIP-123.
findFirstSetBit :: ByteString -> Int Source #
Finding the first set bit's index, as per CIP-123.
data IntegerToByteStringError Source #
Conversion from Integer
to ByteString
, as per
CIP-121.
Structured type to help indicate conversion errors.
Instances
Show IntegerToByteStringError Source # | |
Defined in PlutusCore.Bitwise | |
Eq IntegerToByteStringError Source # | |
Defined in PlutusCore.Bitwise |