mirror of
				https://github.com/StackExchange/dnscontrol.git
				synced 2025-10-31 08:26:26 +08:00 
			
		
		
		
	* 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.
		
			
				
	
	
		
			51 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package models
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"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 {
 | |
| 		return fmt.Errorf("SSHFP algorithm (%v) is not one of 1, 2, 3 or 4", algorithm)
 | |
| 	}
 | |
| 	if fingerprint < 1 && fingerprint > 2 {
 | |
| 		return fmt.Errorf("SSHFP fingerprint (%v) is not one of 1 or 2", fingerprint)
 | |
| 	}
 | |
| 
 | |
| 	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 {
 | |
| 		return fmt.Errorf("SSHFP algorithm does not fit in 8 bits: %w", err)
 | |
| 	}
 | |
| 	i64fingerprint, err := strconv.ParseUint(fingerprint, 10, 8)
 | |
| 	if err != nil {
 | |
| 		return fmt.Errorf("SSHFP fingerprint does not fit in 8 bits: %w", err)
 | |
| 	}
 | |
| 	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 {
 | |
| 		return fmt.Errorf("SSHFP value does not contain 3 fields: (%#v)", s)
 | |
| 	}
 | |
| 	return rc.SetTargetSSHFPStrings(part[0], part[1], StripQuotes(part[2]))
 | |
| }
 |