mirror of
https://github.com/status-im/c-kzg-4844.git
synced 2025-02-16 20:16:37 +00:00
[Go] Make UnmarshalText funcs safer (#306)
* [Go] Make UnmarshalText funcs safer * Run apt update in C# tests
This commit is contained in:
parent
3adec442de
commit
5019e3a08d
2
.github/workflows/csharp-tests.yml
vendored
2
.github/workflows/csharp-tests.yml
vendored
@ -29,7 +29,7 @@ jobs:
|
||||
location: linux-arm64
|
||||
host: ubuntu-22.04
|
||||
ext: .so
|
||||
reqs: sudo apt install -y clang binutils-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross crossbuild-essential-arm64
|
||||
reqs: sudo apt update && sudo apt install -y clang binutils-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross crossbuild-essential-arm64
|
||||
- arch: arm64-darwin
|
||||
location: osx-arm64
|
||||
host: macos-latest
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
// So its functions are available during compilation.
|
||||
@ -68,10 +69,11 @@ func makeErrorFromRet(ret C.C_KZG_RET) error {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
func (b *Bytes32) UnmarshalText(input []byte) error {
|
||||
if string(input[:2]) == "0x" {
|
||||
input = input[2:]
|
||||
inputStr := string(input)
|
||||
if strings.HasPrefix(inputStr, "0x") {
|
||||
inputStr = strings.TrimPrefix(inputStr, "0x")
|
||||
}
|
||||
bytes, err := hex.DecodeString(string(input))
|
||||
bytes, err := hex.DecodeString(inputStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -83,10 +85,11 @@ func (b *Bytes32) UnmarshalText(input []byte) error {
|
||||
}
|
||||
|
||||
func (b *Bytes48) UnmarshalText(input []byte) error {
|
||||
if string(input[:2]) == "0x" {
|
||||
input = input[2:]
|
||||
inputStr := string(input)
|
||||
if strings.HasPrefix(inputStr, "0x") {
|
||||
inputStr = strings.TrimPrefix(inputStr, "0x")
|
||||
}
|
||||
bytes, err := hex.DecodeString(string(input))
|
||||
bytes, err := hex.DecodeString(inputStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -98,10 +101,11 @@ func (b *Bytes48) UnmarshalText(input []byte) error {
|
||||
}
|
||||
|
||||
func (b *Blob) UnmarshalText(input []byte) error {
|
||||
if string(input[:2]) == "0x" {
|
||||
input = input[2:]
|
||||
inputStr := string(input)
|
||||
if strings.HasPrefix(inputStr, "0x") {
|
||||
inputStr = strings.TrimPrefix(inputStr, "0x")
|
||||
}
|
||||
bytes, err := hex.DecodeString(string(input))
|
||||
bytes, err := hex.DecodeString(inputStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user