2018-02-16 01:02:50 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
|
|
|
"fmt"
|
2018-02-16 01:02:50 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetTargetTLSA sets the TLSA fields.
|
|
|
|
func (rc *RecordConfig) SetTargetTLSA(usage, selector, matchingtype uint8, target string) error {
|
|
|
|
rc.TlsaUsage = usage
|
|
|
|
rc.TlsaSelector = selector
|
|
|
|
rc.TlsaMatchingType = matchingtype
|
2018-03-20 05:18:58 +08:00
|
|
|
rc.SetTarget(target)
|
2018-02-16 01:02:50 +08:00
|
|
|
if rc.Type == "" {
|
|
|
|
rc.Type = "TLSA"
|
|
|
|
}
|
|
|
|
if rc.Type != "TLSA" {
|
|
|
|
panic("assertion failed: SetTargetTLSA called when .Type is not TLSA")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetTLSAStrings is like SetTargetTLSA but accepts strings.
|
|
|
|
func (rc *RecordConfig) SetTargetTLSAStrings(usage, selector, matchingtype, target string) (err error) {
|
|
|
|
var i64usage, i64selector, i64matchingtype uint64
|
|
|
|
if i64usage, err = strconv.ParseUint(usage, 10, 8); err == nil {
|
|
|
|
if i64selector, err = strconv.ParseUint(selector, 10, 8); err == nil {
|
|
|
|
if i64matchingtype, err = strconv.ParseUint(matchingtype, 10, 8); err == nil {
|
|
|
|
return rc.SetTargetTLSA(uint8(i64usage), uint8(i64selector), uint8(i64matchingtype), target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
|
|
|
return fmt.Errorf("TLSA has value that won't fit in field: %w", err)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetTLSAString is like SetTargetTLSA but accepts one big string.
|
|
|
|
func (rc *RecordConfig) SetTargetTLSAString(s string) error {
|
|
|
|
part := strings.Fields(s)
|
|
|
|
if len(part) != 4 {
|
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
|
|
|
return fmt.Errorf("TLSA value does not contain 4 fields: (%#v)", s)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
return rc.SetTargetTLSAStrings(part[0], part[1], part[2], part[3])
|
|
|
|
}
|