2019-01-29 06:26:20 +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"
|
2019-01-29 06:26:20 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetTargetSSHFP sets the SSHFP fields.
|
|
|
|
func (rc *RecordConfig) SetTargetSSHFP(algorithm uint8, fingerprint uint8, target string) error {
|
|
|
|
rc.SshfpAlgorithm = algorithm
|
|
|
|
rc.SshfpFingerprint = fingerprint
|
|
|
|
rc.SetTarget(target)
|
|
|
|
if rc.Type == "" {
|
|
|
|
rc.Type = "SSHFP"
|
|
|
|
}
|
|
|
|
if rc.Type != "SSHFP" {
|
|
|
|
panic("assertion failed: SetTargetSSHFP called when .Type is not SSHFP")
|
|
|
|
}
|
|
|
|
|
|
|
|
if algorithm < 1 && algorithm > 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("SSHFP algorithm (%v) is not one of 1, 2, 3 or 4", algorithm)
|
2019-01-29 06:26:20 +08:00
|
|
|
}
|
|
|
|
if fingerprint < 1 && fingerprint > 2 {
|
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("SSHFP fingerprint (%v) is not one of 1 or 2", fingerprint)
|
2019-01-29 06:26:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetSSHFPStrings is like SetTargetSSHFP but accepts strings.
|
|
|
|
func (rc *RecordConfig) SetTargetSSHFPStrings(algorithm, fingerprint, target string) error {
|
|
|
|
i64algorithm, err := strconv.ParseUint(algorithm, 10, 8)
|
|
|
|
if err != nil {
|
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("SSHFP algorithm does not fit in 8 bits: %w", err)
|
2019-01-29 06:26:20 +08:00
|
|
|
}
|
|
|
|
i64fingerprint, err := strconv.ParseUint(fingerprint, 10, 8)
|
|
|
|
if err != nil {
|
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("SSHFP fingerprint does not fit in 8 bits: %w", err)
|
2019-01-29 06:26:20 +08:00
|
|
|
}
|
|
|
|
return rc.SetTargetSSHFP(uint8(i64algorithm), uint8(i64fingerprint), target)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetSSHFPString is like SetTargetSSHFP but accepts one big string.
|
|
|
|
func (rc *RecordConfig) SetTargetSSHFPString(s string) error {
|
|
|
|
part := strings.Fields(s)
|
|
|
|
if len(part) != 3 {
|
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("SSHFP value does not contain 3 fields: (%#v)", s)
|
2019-01-29 06:26:20 +08:00
|
|
|
}
|
|
|
|
return rc.SetTargetSSHFPStrings(part[0], part[1], StripQuotes(part[2]))
|
|
|
|
}
|