replace "if" with "switch" in JA3 and NJA3 code

For clarity.
This commit is contained in:
nervuri 2023-09-20 09:51:41 +00:00
parent 0251e59a10
commit b899c240f4
1 changed files with 10 additions and 8 deletions

View File

@ -48,11 +48,12 @@ func (m *ClientHelloMsg) ja3() {
} }
for _, e := range m.Extensions { for _, e := range m.Extensions {
codeGroups[2] += deGREASE16(e.Code, "") codeGroups[2] += deGREASE16(e.Code, "")
if e.Code == extensionSupportedGroups { switch e.Code {
case extensionSupportedGroups:
for _, g := range e.Data.SupportedGroups { for _, g := range e.Data.SupportedGroups {
codeGroups[3] += deGREASE16(g.(uint16), "") codeGroups[3] += deGREASE16(g.(uint16), "")
} }
} else if e.Code == extensionSupportedPointFormats { case extensionSupportedPointFormats:
for _, pf := range e.Data.SupportedPointFormats { for _, pf := range e.Data.SupportedPointFormats {
codeGroups[4] += toString(pf.(uint8)) + "-" codeGroups[4] += toString(pf.(uint8)) + "-"
} }
@ -95,27 +96,28 @@ func (m *ClientHelloMsg) nja3() {
e.Code = genericGREASECode16 e.Code = genericGREASECode16
} }
extCodes = append(extCodes, e.Code) extCodes = append(extCodes, e.Code)
if e.Code == extensionSupportedGroups { switch e.Code {
case extensionSupportedGroups:
for _, g := range e.Data.SupportedGroups { for _, g := range e.Data.SupportedGroups {
codeGroups[4] += deGREASE16(g.(uint16), genericGreaseString16) codeGroups[4] += deGREASE16(g.(uint16), genericGreaseString16)
} }
} else if e.Code == extensionSupportedPointFormats { case extensionSupportedPointFormats:
for _, pf := range e.Data.SupportedPointFormats { for _, pf := range e.Data.SupportedPointFormats {
codeGroups[5] += toString(pf.(uint8)) + "-" codeGroups[5] += toString(pf.(uint8)) + "-"
} }
} else if e.Code == extensionSupportedVersions { case extensionSupportedVersions:
for _, v := range e.Data.SupportedVersions { for _, v := range e.Data.SupportedVersions {
codeGroups[6] += deGREASE16(v.(uint16), genericGreaseString16) codeGroups[6] += deGREASE16(v.(uint16), genericGreaseString16)
} }
} else if e.Code == extensionSignatureAlgorithms { case extensionSignatureAlgorithms:
for _, sa := range e.Data.SupportedSignatureAlgorithms { for _, sa := range e.Data.SupportedSignatureAlgorithms {
codeGroups[7] += deGREASE16(sa.(uint16), genericGreaseString16) codeGroups[7] += deGREASE16(sa.(uint16), genericGreaseString16)
} }
} else if e.Code == extensionPSKModes { case extensionPSKModes:
for _, mode := range e.Data.PSKModes { for _, mode := range e.Data.PSKModes {
codeGroups[8] += deGREASE8(mode.(uint8), genericGreaseString8) codeGroups[8] += deGREASE8(mode.(uint8), genericGreaseString8)
} }
} else if e.Code == extensionCompressCertificate { case extensionCompressCertificate:
for _, algo := range e.Data.CertificateCompressionAlgos { for _, algo := range e.Data.CertificateCompressionAlgos {
codeGroups[9] += toString(algo.(uint16)) + "-" codeGroups[9] += toString(algo.(uint16)) + "-"
} }