Documentation
¶
Index ¶
- type CompactBitArray
- func (bA *CompactBitArray) CompactMarshal() []byte
- func (bA *CompactBitArray) Copy() *CompactBitArray
- func (bA *CompactBitArray) GetIndex(i int) bool
- func (bA *CompactBitArray) MarshalJSON() ([]byte, error)
- func (bA *CompactBitArray) NumTrueBitsBefore(index int) int
- func (bA *CompactBitArray) SetIndex(i int, v bool) bool
- func (bA *CompactBitArray) Size() int
- func (bA *CompactBitArray) String() string
- func (bA *CompactBitArray) StringIndented(indent string) string
- func (bA *CompactBitArray) UnmarshalJSON(bz []byte) error
- func (bA *CompactBitArray) ValidateBasic() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompactBitArray ¶
type CompactBitArray struct {
ExtraBitsStored byte `json:"extra_bits"` // The number of extra bits in elems.
Elems []byte `json:"bits"`
}
CompactBitArray is an implementation of a space efficient bit array. This is used to ensure that the encoded data takes up a minimal amount of space after amino encoding. This is not thread safe, and is not intended for concurrent usage.
func CompactUnmarshal ¶
func CompactUnmarshal(bz []byte) (*CompactBitArray, error)
CompactUnmarshal is a space efficient decoding for CompactBitArray. It is not amino compatible.
func NewCompactBitArray ¶
func NewCompactBitArray(bits int) *CompactBitArray
NewCompactBitArray returns a new compact bit array. It returns nil if the number of bits is zero.
func (*CompactBitArray) CompactMarshal ¶
func (bA *CompactBitArray) CompactMarshal() []byte
CompactMarshal is a space efficient encoding for CompactBitArray. It is not amino compatible.
func (*CompactBitArray) Copy ¶
func (bA *CompactBitArray) Copy() *CompactBitArray
Copy returns a copy of the provided bit array.
func (*CompactBitArray) GetIndex ¶
func (bA *CompactBitArray) GetIndex(i int) bool
GetIndex returns the bit at index i within the bit array. The behavior is undefined if i >= bA.Size()
func (*CompactBitArray) MarshalJSON ¶
func (bA *CompactBitArray) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface by marshaling bit array using a custom format: a string of '-' or 'x' where 'x' denotes the 1 bit.
func (*CompactBitArray) NumTrueBitsBefore ¶
func (bA *CompactBitArray) NumTrueBitsBefore(index int) int
NumTrueBitsBefore returns the number of bits set to true before the given index. e.g. if bA = _XX__XX, NumOfTrueBitsBefore(4) = 2, since there are two bits set to true before index 4.
func (*CompactBitArray) SetIndex ¶
func (bA *CompactBitArray) SetIndex(i int, v bool) bool
SetIndex sets the bit at index i within the bit array. The behavior is undefined if i >= bA.Size()
func (*CompactBitArray) Size ¶
func (bA *CompactBitArray) Size() int
Size returns the number of bits in the bitarray
func (*CompactBitArray) String ¶
func (bA *CompactBitArray) String() string
String returns a string representation of CompactBitArray: BA{<bit-string>}, where <bit-string> is a sequence of 'x' (1) and '_' (0). The <bit-string> includes spaces and newlines to help people. For a simple sequence of 'x' and '_' characters with no spaces or newlines, see the MarshalJSON() method. Example: "BA{_x_}" or "nil-BitArray" for nil.
func (*CompactBitArray) StringIndented ¶
func (bA *CompactBitArray) StringIndented(indent string) string
StringIndented returns the same thing as String(), but applies the indent at every 10th bit, and twice at every 50th bit.
func (*CompactBitArray) UnmarshalJSON ¶
func (bA *CompactBitArray) UnmarshalJSON(bz []byte) error
UnmarshalJSON implements json.Unmarshaler interface by unmarshaling a custom JSON description.
func (*CompactBitArray) ValidateBasic ¶
func (bA *CompactBitArray) ValidateBasic() error
ValidateBasic returns an error unless bA holds exactly the Size() bits it claims, as NewCompactBitArray and SetIndex produce one. It is the counterpart, for this type, of bitarray.BitArray.ValidateBasic.
A CompactBitArray decoded from an untrusted transaction signature has neither of the properties below for free, and anything making an authorization decision from one needs both:
- ExtraBitsStored comes off the wire and is never checked against len(Elems), so Size() may claim more bits than Elems holds. GetIndex bounds its index against Size(), not against len(Elems), so every index from len(Elems)*8 up to Size() indexes past the end of the slice. This is the load-bearing half: without it the walk reads out of bounds and panics.
- Bits past Size() are never read at all, so a value that sets them says something the type cannot mean. Rejecting what nothing interprets keeps the accepted set equal to the set signers can produce.
It does NOT make the wire encoding of a bit array unique, and nothing here should be read as claiming that: amino's decoder accepts non-minimal uvarints and explicitly-written zero-valued fields, so ExtraBitsStored alone has several accepted encodings of the same value. Byte-level canonicality is an amino property, not one this function can establish.
A nil bit array is not an error here, the same as for BitArray: Size() is 0 for one, which the callers already reject against their own key.