-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add golangci-lint and fix lint issues; add ci for macOS and windows #36
Conversation
0ce2bfa
to
8f448d8
Compare
85aaaf7
to
348c87a
Compare
crypto/ciphers.go
Outdated
"fmt" | ||
"runtime" | ||
"unsafe" | ||
) | ||
|
||
const ( | ||
GCM_TAG_MAXLEN = 16 | ||
GcmTagMaxLen = 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照go的命名规格,如果本身是缩写,那就保留大写 GcmTagMaxLen => GCMTagMaxLen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
crypto/sm2/sm2.go
Outdated
@@ -24,27 +20,37 @@ import ( | |||
|
|||
// VerifyASN1 verifies ASN.1 encoded signature. Returns nil on success. | |||
func VerifyASN1(pub crypto.PublicKey, data, sig []byte) error { | |||
if pub.KeyType() != crypto.NID_sm2 { | |||
return errors.New("SM2: key type is not sm2") | |||
if pub.KeyType() != crypto.NidSm2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同理, NIDSM2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
ssl.go
Outdated
@@ -32,37 +32,35 @@ const ( | |||
) | |||
|
|||
const ( | |||
OPENSSL_NPN_NEGOTIATED C.int = C.OPENSSL_NPN_NEGOTIATED | |||
OPENSSL_NPN_NO_OVERLAP C.int = C.OPENSSL_NPN_NO_OVERLAP | |||
NpnNegotiated C.int = C.OPENSSL_NPN_NEGOTIATED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPNNegotiated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
//export sni_cb_thunk | ||
func sni_cb_thunk(p unsafe.Pointer, con *C.SSL, ad unsafe.Pointer, arg unsafe.Pointer) C.int { | ||
//export sniCbThunk | ||
func sniCbThunk(callback unsafe.Pointer, con *C.SSL, ad unsafe.Pointer, arg unsafe.Pointer) C.int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func sniCbThunk(callback unsafe.Pointer, con *C.SSL, _ unsafe.Pointer, _ unsafe.Pointer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用两个下划线会导致编译失败。
ssl_test.go
Outdated
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_ = serverConn.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ignore the error return by Close() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if err != nil { | ||
t.Error(err) | ||
} | ||
tls_key, ok := tls_cert.PrivateKey.(*rsa.PrivateKey) | ||
|
||
tlsKey, ok := tlsCert.PrivateKey.(*rsa.PrivateKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_, ok := tlsCert.PrivateKey.(*rsa.PrivateKey)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
ctx := C.X_EVP_MD_CTX_new() | ||
defer C.X_EVP_MD_CTX_free(ctx) | ||
|
||
if key.KeyType() == KeyTypeED25519 { | ||
// do ED specific one-shot sign | ||
if method != nil || len(data) == 0 { | ||
return nil, errors.New("signpkcs1v15: 0-length data or non-null digest") | ||
return nil, ErrNilParameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不wrapper一层error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得没啥必要,ErrNilParameter表示参数为空就可以了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,这里是keytype 是specific KeyTypeED25519的时候对应的错误,加wrapper 可能更好区分。如果上层不需要区分也OK
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]), | ||
C.int(len(pem_block))) | ||
|
||
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pemBlock[0]), C.int(len(pemBlock))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑 C.CBytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要使用C.CBytes()拷贝一份内存
conn.go
Outdated
want_read_future *utils.Future | ||
conn net.Conn | ||
ctx *Ctx // for gc | ||
intoSsl *crypto.ReadBio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intoSSL
fromSSL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
return 0, func() error { return io.EOF } | ||
} | ||
runtime.LockOSThread() | ||
defer runtime.UnlockOSThread() | ||
rv, errno := C.SSL_read(c.ssl, unsafe.Pointer(&b[0]), C.int(len(b))) | ||
rv, errno := C.SSL_read(c.ssl, unsafe.Pointer(&buf[0]), C.int(len(buf))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C.CBytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSL_read()直接写到buf里面,不用使用C.CBytes()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, 确保c 不会free go alloc 的内存就没问题
crypto/cert.go
Outdated
} | ||
runtime.LockOSThread() | ||
defer runtime.UnlockOSThread() | ||
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]), | ||
C.int(len(pem_block))) | ||
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pemBlock[0]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C.CBytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要使用C.CBytes()拷贝一份内存
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, 确保c 不会free go alloc 的内存就没问题
CI adds golangci-lint check. Delete duplicate cgo ldflags -lcrypto Fix golangci-lint issues. - Set max length of line to 120 - Test cases add t.Parallel() - Test helpers add t.Helper() - Warp the error with fmt.Errorf() - Rename variables from C style to Golang style - Add blank line. Add CI for macOS and Windows. Fix ldflags for windows. Fix compile errors on windows.
348c87a
to
ffe81af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CI adds golangci-lint check.
Delete duplicate cgo ldflags -lcrypto
Fix golangci-lint issues.
Add CI for macOS and Windows.
Fix ldflags for windows.
Fix compile errors on windows.