Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainbourgeois committed Jan 16, 2024
1 parent 0ff8815 commit 16bf113
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: golangci/[email protected]
with:
version: latest
args: -v --config ./.golangci.yml
args: run

license-check:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ linters-settings:
misspell:
#locale: US
ignore-words:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
wsl:
# If true append is only allowed to be cuddled if appending value is
# matching variables, fields or types on line above. Default is true.
Expand Down
59 changes: 31 additions & 28 deletions aper.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (pd *perBitData) parseConstraintValue(valueRange int64) (value uint64, err
if valueRange <= 255 {
if valueRange < 0 {
err = fmt.Errorf("Value range is negative")
return
return value, err
}
var i uint
// 1 ~ 8 bits
Expand All @@ -161,17 +161,17 @@ func (pd *perBitData) parseConstraintValue(valueRange int64) (value uint64, err
}
}
value, err = pd.getBitsValue(i)
return
return value, err
} else if valueRange == 256 {
bytes = 1
} else if valueRange <= 65536 {
bytes = 2
} else {
err = fmt.Errorf("Constraint Value is large than 65536")
return
return value, err
}
if err = pd.parseAlignBits(); err != nil {
return
return value, err
}
value, err = pd.getBitsValue(bytes * 8)
return value, err
Expand All @@ -181,17 +181,17 @@ func (pd *perBitData) parseSemiConstrainedWholeNumber(lb uint64) (value uint64,
var repeat bool
var length uint64
if length, err = pd.parseLength(-1, &repeat); err != nil {
return
return value, err
}
if length > 8 || repeat {
err = fmt.Errorf("Too long length: %d", length)
return
return value, err
}
if value, err = pd.getBitsValue(uint(length) * 8); err != nil {
return
return value, err
}
value += lb
return
return value, err
}

func (pd *perBitData) parseNormallySmallNonNegativeWholeNumber() (value uint64, err error) {
Expand All @@ -218,27 +218,27 @@ func (pd *perBitData) parseLength(sizeRange int64, repeat *bool) (value uint64,
}

if err = pd.parseAlignBits(); err != nil {
return
return value, err
}
firstByte, err := pd.getBitsValue(8)
if err != nil {
return
return value, err
}
if (firstByte & 128) == 0 { // #10.9.3.6
value = firstByte & 0x7F
return
return value, err
} else if (firstByte & 64) == 0 { // #10.9.3.7
var secondByte uint64
if secondByte, err = pd.getBitsValue(8); err != nil {
return
return value, err
}
value = ((firstByte & 63) << 8) | secondByte
return
return value, err
}
firstByte &= 63
if firstByte < 1 || firstByte > 4 {
err = fmt.Errorf("Parse Length Out of Constraint")
return
return value, err
}
*repeat = true
value = 16384 * firstByte
Expand Down Expand Up @@ -335,7 +335,8 @@ func (pd *perBitData) parseBitString(extensed bool, lowerBoundPtr *int64, upperB
}

func (pd *perBitData) parseOctetString(extensed bool, lowerBoundPtr *int64, upperBoundPtr *int64) (
OctetString, error) {
OctetString, error,
) {
var lb, ub, sizeRange int64 = 0, -1, -1
if !extensed {
if lowerBoundPtr != nil {
Expand Down Expand Up @@ -513,7 +514,8 @@ func (pd *perBitData) parseInteger(extensed bool, lowerBoundPtr *int64, upperBou
}

func (pd *perBitData) parseEnumerated(extensed bool, lowerBoundPtr *int64, upperBoundPtr *int64) (value uint64,
err error) {
err error,
) {
if lowerBoundPtr == nil || upperBoundPtr == nil {
err = fmt.Errorf("ENUMERATED value constraint is error")
return
Expand Down Expand Up @@ -542,7 +544,8 @@ func (pd *perBitData) parseEnumerated(extensed bool, lowerBoundPtr *int64, upper
}

func (pd *perBitData) parseSequenceOf(sizeExtensed bool, params fieldParameters, sliceType reflect.Type) (
reflect.Value, error) {
reflect.Value, error,
) {
var sliceContent reflect.Value
var lb int64 = 0
var sizeRange int64
Expand Down Expand Up @@ -908,17 +911,17 @@ func parseField(v reflect.Value, pd *perBitData, params fieldParameters) error {
//
// The following tags on struct fields have special meaning to Unmarshal:
//
// optional OPTIONAL tag in SEQUENCE
// sizeExt specifies that size is extensible
// valueExt specifies that value is extensible
// sizeLB set the minimum value of size constraint
// sizeUB set the maximum value of value constraint
// valueLB set the minimum value of size constraint
// valueUB set the maximum value of value constraint
// default sets the default value
// openType specifies the open Type
// referenceFieldName the string of the reference field for this type (only if openType used)
// referenceFieldValue the corresponding value of the reference field for this type (only if openType used)
// optional OPTIONAL tag in SEQUENCE
// sizeExt specifies that size is extensible
// valueExt specifies that value is extensible
// sizeLB set the minimum value of size constraint
// sizeUB set the maximum value of value constraint
// valueLB set the minimum value of size constraint
// valueUB set the maximum value of value constraint
// default sets the default value
// openType specifies the open Type
// referenceFieldName the string of the reference field for this type (only if openType used)
// referenceFieldValue the corresponding value of the reference field for this type (only if openType used)
//
// Other ASN.1 types are not supported; if it encounters them,
// Unmarshal returns a parse error.
Expand Down
10 changes: 5 additions & 5 deletions aper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ var intTest2Data = []intTest2{
{3},
}

// 2 <= bmax-bmin <= 255
// 2 <= bmax-bmin <= 255
type intTest3 struct {
Value int64 `aper:"valueLB:1,valueUB:110"`
}
Expand All @@ -462,7 +462,7 @@ var intTest3Data = []intTest3{
{110},
}

// bmax-bmin == 256
// bmax-bmin == 256
type intTest4 struct {
Value int64 `aper:"valueLB:0,valueUB:255"`
}
Expand All @@ -471,7 +471,7 @@ var intTest4Data = []intTest4{
{140},
}

// 257 <= bmax-bmin <= 65536
// 257 <= bmax-bmin <= 65536
type intTest5 struct {
Value int64 `aper:"valueLB:0,valueUB:65535"`
}
Expand All @@ -480,7 +480,7 @@ var intTest5Data = []intTest5{
{140},
}

// 65537 <= bmax-bmin
// 65537 <= bmax-bmin
type intTest6 struct {
Value int64 `aper:"valueLB:0,valueUB:4294967295"`
}
Expand All @@ -492,7 +492,7 @@ var intTest6Data = []intTest6{
{65536},
}

// value extensed
// value extensed
type intTest7 struct {
Value int64 `aper:"valueExt,valueLB:0,valueUB:45"`
}
Expand Down
9 changes: 6 additions & 3 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func (pd *perRawBitData) appendLength(sizeRange int64, value uint64) (err error)
}

func (pd *perRawBitData) appendBitString(bytes []byte, bitsLength uint64, extensive bool,
lowerBoundPtr *int64, upperBoundPtr *int64) error {
lowerBoundPtr *int64, upperBoundPtr *int64,
) error {
var err error
var lb, ub, sizeRange int64 = 0, -1, -1
if lowerBoundPtr != nil {
Expand Down Expand Up @@ -277,7 +278,8 @@ func (pd *perRawBitData) appendBitString(bytes []byte, bitsLength uint64, extens
}

func (pd *perRawBitData) appendOctetString(bytes []byte, extensive bool, lowerBoundPtr *int64,
upperBoundPtr *int64) error {
upperBoundPtr *int64,
) error {
byteLen := uint64(len(bytes))
var lb, ub, sizeRange int64 = 0, -1, -1
if lowerBoundPtr != nil {
Expand Down Expand Up @@ -482,7 +484,8 @@ func (pd *perRawBitData) appendInteger(value int64, extensive bool, lowerBoundPt
}

func (pd *perRawBitData) appendEnumerated(value uint64, extensive bool, lowerBoundPtr *int64,
upperBoundPtr *int64) error {
upperBoundPtr *int64,
) error {
if lowerBoundPtr == nil || upperBoundPtr == nil {
return fmt.Errorf("ENUMERATED value constraint is error")
}
Expand Down

0 comments on commit 16bf113

Please sign in to comment.