run nix fmt

This commit is contained in:
Abel Luck 2025-09-10 14:14:13 +02:00
parent 7f6d7cc0c4
commit 139f5f6d9c
3 changed files with 19 additions and 19 deletions

View file

@ -215,14 +215,14 @@ func (r *TorRelayIdentityEd25519Resource) encodeTorPrivateKey(privateKey ed25519
// Tor Ed25519 private key format: // Tor Ed25519 private key format:
// "== ed25519v1-secret: type0 ==" + null bytes + 64 bytes key data // "== ed25519v1-secret: type0 ==" + null bytes + 64 bytes key data
header := "== ed25519v1-secret: type0 ==" header := "== ed25519v1-secret: type0 =="
// Create 96-byte buffer: 32 bytes header + null padding + 64 bytes key // Create 96-byte buffer: 32 bytes header + null padding + 64 bytes key
torKey := make([]byte, 96) torKey := make([]byte, 96)
copy(torKey, header) copy(torKey, header)
// Copy the private key (64 bytes) starting at offset 32 // Copy the private key (64 bytes) starting at offset 32
copy(torKey[32:], privateKey) copy(torKey[32:], privateKey)
return base64.StdEncoding.EncodeToString(torKey) return base64.StdEncoding.EncodeToString(torKey)
} }
@ -230,13 +230,13 @@ func (r *TorRelayIdentityEd25519Resource) encodeTorPublicKey(publicKey ed25519.P
// Tor Ed25519 public key format: // Tor Ed25519 public key format:
// "== ed25519v1-public: type0 ==" + null bytes + 32 bytes key data // "== ed25519v1-public: type0 ==" + null bytes + 32 bytes key data
header := "== ed25519v1-public: type0 ==" header := "== ed25519v1-public: type0 =="
// Create 64-byte buffer: 32 bytes header + null padding + 32 bytes key // Create 64-byte buffer: 32 bytes header + null padding + 32 bytes key
torKey := make([]byte, 64) torKey := make([]byte, 64)
copy(torKey, header) copy(torKey, header)
// Copy the public key (32 bytes) starting at offset 32 // Copy the public key (32 bytes) starting at offset 32
copy(torKey[32:], publicKey) copy(torKey[32:], publicKey)
return base64.StdEncoding.EncodeToString(torKey) return base64.StdEncoding.EncodeToString(torKey)
} }

View file

@ -38,15 +38,15 @@ func TestAccTorRelayIdentityEd25519Resource(t *testing.T) {
func TestTorEd25519FingerprintGeneration(t *testing.T) { func TestTorEd25519FingerprintGeneration(t *testing.T) {
testPubKeyBase64 := "PT0gZWQyNTUxOXYxLXB1YmxpYzogdHlwZTAgPT0AAAB6UEqfT3OvqdpNfw/rbOucsc5AXRUw4lcy/SaWxruoYA==" testPubKeyBase64 := "PT0gZWQyNTUxOXYxLXB1YmxpYzogdHlwZTAgPT0AAAB6UEqfT3OvqdpNfw/rbOucsc5AXRUw4lcy/SaWxruoYA=="
expectedFingerprint := "elBKn09zr6naTX8P62zrnLHOQF0VMOJXMv0mlsa7qGA" expectedFingerprint := "elBKn09zr6naTX8P62zrnLHOQF0VMOJXMv0mlsa7qGA"
pubKeyBytes, err := base64.StdEncoding.DecodeString(testPubKeyBase64) pubKeyBytes, err := base64.StdEncoding.DecodeString(testPubKeyBase64)
if err != nil { if err != nil {
t.Fatalf("Failed to decode test public key: %v", err) t.Fatalf("Failed to decode test public key: %v", err)
} }
actualFingerprint := base64.StdEncoding.EncodeToString(pubKeyBytes[32:]) actualFingerprint := base64.StdEncoding.EncodeToString(pubKeyBytes[32:])
actualFingerprint = regexp.MustCompile(`=*$`).ReplaceAllString(actualFingerprint, "") actualFingerprint = regexp.MustCompile(`=*$`).ReplaceAllString(actualFingerprint, "")
if actualFingerprint != expectedFingerprint { if actualFingerprint != expectedFingerprint {
t.Errorf("Expected fingerprint %s, got %s", expectedFingerprint, actualFingerprint) t.Errorf("Expected fingerprint %s, got %s", expectedFingerprint, actualFingerprint)
} }
@ -72,16 +72,16 @@ func TestAccTorRelayIdentityEd25519TorFormat(t *testing.T) {
func TestTorEd25519FormatEncoding(t *testing.T) { func TestTorEd25519FormatEncoding(t *testing.T) {
testPubKeyBase64 := "PT0gZWQyNTUxOXYxLXB1YmxpYzogdHlwZTAgPT0AAAB6UEqfT3OvqdpNfw/rbOucsc5AXRUw4lcy/SaWxruoYA==" testPubKeyBase64 := "PT0gZWQyNTUxOXYxLXB1YmxpYzogdHlwZTAgPT0AAAB6UEqfT3OvqdpNfw/rbOucsc5AXRUw4lcy/SaWxruoYA=="
pubKeyBytes, err := base64.StdEncoding.DecodeString(testPubKeyBase64) pubKeyBytes, err := base64.StdEncoding.DecodeString(testPubKeyBase64)
if err != nil { if err != nil {
t.Fatalf("Failed to decode test public key: %v", err) t.Fatalf("Failed to decode test public key: %v", err)
} }
if len(pubKeyBytes) != 64 { if len(pubKeyBytes) != 64 {
t.Errorf("Expected public key to be 64 bytes, got %d", len(pubKeyBytes)) t.Errorf("Expected public key to be 64 bytes, got %d", len(pubKeyBytes))
} }
expectedHeader := "== ed25519v1-public: type0 ==" expectedHeader := "== ed25519v1-public: type0 =="
actualHeader := string(pubKeyBytes[:len(expectedHeader)]) actualHeader := string(pubKeyBytes[:len(expectedHeader)])
if actualHeader != expectedHeader { if actualHeader != expectedHeader {

View file

@ -31,13 +31,13 @@ func NewTorRelayIdentityRsaResource() resource.Resource {
type TorRelayIdentityRsaResource struct{} type TorRelayIdentityRsaResource struct{}
type TorRelayIdentityRsaResourceModel struct { type TorRelayIdentityRsaResourceModel struct {
Id types.String `tfsdk:"id"` Id types.String `tfsdk:"id"`
Algorithm types.String `tfsdk:"algorithm"` Algorithm types.String `tfsdk:"algorithm"`
PrivateKeyPem types.String `tfsdk:"private_key_pem"` PrivateKeyPem types.String `tfsdk:"private_key_pem"`
PublicKeyPem types.String `tfsdk:"public_key_pem"` PublicKeyPem types.String `tfsdk:"public_key_pem"`
PublicKeyFingerprintSha1 types.String `tfsdk:"public_key_fingerprint_sha1"` PublicKeyFingerprintSha1 types.String `tfsdk:"public_key_fingerprint_sha1"`
PublicKeyFingerprintSha256 types.String `tfsdk:"public_key_fingerprint_sha256"` PublicKeyFingerprintSha256 types.String `tfsdk:"public_key_fingerprint_sha256"`
PublicKeyFingerprintSha1Hashed types.String `tfsdk:"public_key_fingerprint_sha1_hashed"` PublicKeyFingerprintSha1Hashed types.String `tfsdk:"public_key_fingerprint_sha1_hashed"`
} }
func (r *TorRelayIdentityRsaResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { func (r *TorRelayIdentityRsaResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {