Refine unsafe usage

This commit is contained in:
风扇滑翔翼 2025-07-11 14:14:00 +00:00 committed by GitHub
parent d8557bf279
commit bcb11ad45f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -129,10 +129,9 @@ func printTLSConnDetail(tlsConn *gotls.Conn) {
tlsVersion = "TLS 1.2" tlsVersion = "TLS 1.2"
} }
fmt.Println("TLS Version:", tlsVersion) fmt.Println("TLS Version:", tlsVersion)
p, _ := reflect.TypeOf(tlsConn).Elem().FieldByName("curveID") curveID := *(*gotls.CurveID)(unsafe.Pointer(reflect.ValueOf(tlsConn).Elem().FieldByName("curveID").UnsafeAddr()))
curveID := (*gotls.CurveID)(unsafe.Pointer(uintptr(unsafe.Pointer(tlsConn)) + p.Offset)) if curveID != 0 {
if curveID != nil { PostQuantum := (curveID == gotls.X25519MLKEM768)
PostQuantum := (*curveID == gotls.X25519MLKEM768)
fmt.Println("Post-Quantum key exchange:", PostQuantum, "("+curveID.String()+")") fmt.Println("Post-Quantum key exchange:", PostQuantum, "("+curveID.String()+")")
} else { } else {
fmt.Println("Post-Quantum key exchange: false (RSA Exchange)") fmt.Println("Post-Quantum key exchange: false (RSA Exchange)")