services
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package keygen
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: ${SRCDIR}/legacy/keygen.a -lm
|
||||
#include <keygen.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func GenerateKey(vid int) string {
|
||||
var key [C.TOK_SIZE]byte
|
||||
keyPtr := (*C.char)(unsafe.Pointer(&key[0]))
|
||||
C.GenerateToken(C.int(vid), keyPtr)
|
||||
res := strings.Builder{}
|
||||
for _, v := range key {
|
||||
res.WriteByte(v)
|
||||
}
|
||||
return res.String()
|
||||
}
|
||||
|
||||
func ValidateKey(token string, vid int) bool {
|
||||
res := C.ValidateToken(C.int(vid), C.CString(token))
|
||||
return res == 1
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by john on 1/24/20.
|
||||
//
|
||||
|
||||
#ifndef KEYGEN_KEYGEN_H
|
||||
#define KEYGEN_KEYGEN_H
|
||||
|
||||
#define TOK_SIZE 30
|
||||
|
||||
void GenerateToken(int n, char* out);
|
||||
int ValidateToken(int n, char* token);
|
||||
#endif //KEYGEN_KEYGEN_H
|
||||
Binary file not shown.
Reference in New Issue
Block a user