{"record":{"id":"de10cb0acddf47c0","repo":"OpenNHP/opennhp","slug":"unknown-mode-s","errorCode":null,"errorMessage":"unknown mode: %s","messagePattern":"unknown mode: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/core/ztdo/noise.go","lineNumber":214,"sourceCode":"func (d DataKeyPairECCMode) ToHashType() core.HashTypeEnum {\n\tswitch d {\n\tcase CURVE25519:\n\t\treturn core.HASH_SHA256\n\tcase SM2:\n\t\treturn core.HASH_SM3\n\tdefault:\n\t\treturn core.HASH_SHA256\n\t}\n}\n\nfunc NewDataKeyPairECCModeWithName(mode string) (DataKeyPairECCMode, error) {\n\tswitch mode {\n\tcase \"CURVE25519\":\n\t\treturn CURVE25519, nil\n\tcase \"SM2\":\n\t\treturn SM2, nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unknown mode: %s\", mode)\n\t}\n}\n\nfunc NewDataKeyPairECCMode(eccMode core.EccTypeEnum) (DataKeyPairECCMode, error) {\n\tswitch eccMode {\n\tcase core.ECC_CURVE25519:\n\t\treturn CURVE25519, nil\n\tcase core.ECC_SM2:\n\t\treturn SM2, nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unknown mode: %d\", eccMode)\n\t}\n}\n\nfunc (d DataKeyPairECCMode) ECDHFromKey(prk []byte) core.Ecdh {\n\treturn core.ECDHFromKey(d.ToEccType(), prk)\n}\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/core/ztdo/noise.go#L196-L232","documentation":"NewDataKeyPairECCModeWithName maps an ECC curve name string to a DataKeyPairECCMode. Only \"CURVE25519\" and \"SM2\" are accepted; anything else returns this error. It enforces the closed set of elliptic curves supported for data key pairs in the ztdo package.","triggerScenarios":"Calling NewDataKeyPairECCModeWithName with a name other than exactly \"CURVE25519\" or \"SM2\" — e.g. \"curve25519\", \"P-256\", \"ed25519\" (nhp/core/ztdo/noise.go:214).","commonSituations":"Config files using lowercase curve names or NIST curve names; protocol negotiation tables listing curves this build doesn't support; typos like \"Curve25519\".","solutions":["Pass exactly \"CURVE25519\" or \"SM2\" (uppercase, exact match)","Normalize/uppercase the config value before calling, or map aliases to the accepted names","Align peer negotiation to only offer supported curves"],"exampleFix":"// before\nmode, err := NewDataKeyPairECCModeWithName(cfg.Curve) // \"curve25519\"\n// after\nmode, err := NewDataKeyPairECCModeWithName(strings.ToUpper(cfg.Curve)) // \"CURVE25519\"","handlingStrategy":"validation","validationCode":"if name != \"CURVE25519\" && name != \"SM2\" {\n\treturn fmt.Errorf(\"unsupported ECC curve %q\", name)\n}","typeGuard":null,"tryCatchPattern":"mode, err := NewDataKeyPairECCModeWithName(name)\nif err != nil {\n\tmode, err = NewDataKeyPairECCModeWithName(\"CURVE25519\") // default curve\n}","preventionTips":["Use constants for curve names","Uppercase/normalize external input before lookup","Reject unsupported curves at config validation time"],"tags":["go","crypto","ecc","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}