Home Page
This commit is contained in:
24
go/ctils.go
Normal file
24
go/ctils.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
//export prepareCStringArray
|
||||
func prepareCStringArray(goStrings []string) (**C.char, int) {
|
||||
cStrings := make([]*C.char, len(goStrings))
|
||||
for i, s := range goStrings {
|
||||
cStrings[i] = C.CString(s)
|
||||
}
|
||||
return (**C.char)(unsafe.Pointer(&cStrings[0])), len(goStrings)
|
||||
}
|
||||
|
||||
//export freeCStringArray
|
||||
func freeCStringArray(cStrings **C.char, length int) {
|
||||
array := (*[1 << 30]*C.char)(unsafe.Pointer(cStrings))[:length:length]
|
||||
for _, s := range array {
|
||||
C.free(unsafe.Pointer(s))
|
||||
}
|
||||
}
|
||||
18
go/totp.go
18
go/totp.go
@@ -10,10 +10,12 @@ import (
|
||||
"hash"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var token string
|
||||
@@ -119,17 +121,25 @@ func loadConfigs() {
|
||||
Format: format,
|
||||
}
|
||||
|
||||
configs[fileEntry.Name()] = config
|
||||
fileName := fileEntry.Name()
|
||||
ext := filepath.Ext(fileName)
|
||||
|
||||
configs[strings.TrimSuffix(fileName, ext)] = config
|
||||
}
|
||||
}
|
||||
|
||||
//export getConfigNames
|
||||
func getConfigNames() []string {
|
||||
func getConfigNames() (**C.char, C.int) {
|
||||
names := make([]string, 0, len(configs))
|
||||
for name := range configs {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
cStrings := make([]*C.char, len(names))
|
||||
for i, name := range names {
|
||||
cStrings[i] = C.CString(name)
|
||||
}
|
||||
|
||||
return (**C.char)(unsafe.Pointer(&cStrings[0])), C.int(len(names))
|
||||
}
|
||||
|
||||
//export getCode
|
||||
@@ -150,4 +160,4 @@ func getTimeRemainingMS(n int) uint64 {
|
||||
return (uint64(n) * 1000) - (uint64(time.Now().UnixNano()/1e6) % (uint64(n) * 1000))
|
||||
}
|
||||
|
||||
func main() {}
|
||||
//func main() {}
|
||||
|
||||
Reference in New Issue
Block a user