{"record":{"id":"e75200bc46046acd","repo":"AlexxIT/go2rtc","slug":"hap-wrong-pin-format","errorCode":null,"errorMessage":"hap: wrong PIN format: ","messagePattern":"hap: wrong PIN format: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hap/helpers.go","lineNumber":82,"sourceCode":"type JSONCharacters struct {\n\tValue []JSONCharacter `json:\"characteristics\"`\n}\n\ntype JSONCharacter struct {\n\tAID    uint8  `json:\"aid\"`\n\tIID    uint64 `json:\"iid\"`\n\tStatus any    `json:\"status,omitempty\"`\n\tValue  any    `json:\"value,omitempty\"`\n\tEvent  any    `json:\"ev,omitempty\"`\n}\n\n// 4.2.1.2 Invalid Setup Codes\nconst insecurePINs = \"00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999 12345678 87654321\"\n\nfunc SanitizePin(pin string) (string, error) {\n\ts := strings.ReplaceAll(pin, \"-\", \"\")\n\tif len(s) != 8 {\n\t\treturn \"\", errors.New(\"hap: wrong PIN format: \" + pin)\n\t}\n\tif strings.Contains(insecurePINs, s) {\n\t\treturn \"\", errors.New(\"hap: insecure PIN: \" + pin)\n\t}\n\t// 123-45-678\n\treturn s[:3] + \"-\" + s[3:5] + \"-\" + s[5:], nil\n}\n\nfunc GenerateKey() []byte {\n\t_, key, _ := ed25519.GenerateKey(nil)\n\treturn key\n}\n\nfunc GenerateUUID() string {\n\t//12345678-9012-3456-7890-123456789012\n\tdata := make([]byte, 16)\n\t_, _ = rand.Read(data)\n\ts := hex.EncodeToString(data)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/hap/helpers.go#L64-L100","documentation":"HAP SanitizePin format guard: after stripping dashes, the PIN is not exactly 8 characters (the HAP standard setup-code length). The offending PIN is appended. Purely an input-format check — credentials were supplied in the wrong shape before any server contact.","triggerScenarios":"Thrown at pkg/hap/helpers.go:82 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide the setup code as 8 digits, optionally dashed (e.g. 123-45-678)","Strip spaces or other characters introduced by copy-paste","Validate the PIN field in config/UI before calling Init or Pair"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}