Skip to content
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 go.mod file #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ sudo: false
language: go

go:
- 1.4
- 1.13.4

os:
- linux
6 changes: 4 additions & 2 deletions crypt.go → crypt_bsd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin freebsd netbsd
// +build freebsd openbsd

// Package crypt provides wrappers around functions available in crypt.h
//
Expand Down Expand Up @@ -40,7 +40,9 @@ func Crypt(pass, salt string) (string, error) {
if c_enc == nil {
return "", err
}
defer C.free(unsafe.Pointer(c_enc))
// returned pointer points to static data which is overwritten
// in each call, so dont free it
// defer C.free(unsafe.Pointer(c_enc))

// Return nil error if the string is non-nil.
// As per the errno.h manpage, functions are allowed to set errno
Expand Down
11 changes: 5 additions & 6 deletions crypt_r.go → crypt_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import (
"unsafe"
)


/*
#cgo LDFLAGS: -lcrypt

#define _GNU_SOURCE

#include <stdlib.h>
#include <string.h>
#include <crypt.h>
#include <stdlib.h> // for NULL
#include <string.h> // for strlen
#include <crypt.h> // for crypt()

char *gnu_ext_crypt(char *pass, char *salt) {
char *enc = NULL;
Expand All @@ -32,7 +31,7 @@ char *gnu_ext_crypt(char *pass, char *salt) {
}

ret = (char *)malloc(strlen(enc)+1); // for trailing null
strncpy(ret, enc, strlen(enc));
memcpy(ret, enc, strlen(enc));
ret[strlen(enc)]= '\0'; // paranoid

return ret;
Expand Down
8 changes: 0 additions & 8 deletions crypt_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package crypt

import (
"strings"
"testing"
)

Expand Down Expand Up @@ -40,13 +39,6 @@ func TestCryptMD5(t *testing.T) {
}

func TestCryptErrors(t *testing.T) {
FixedMinorVersion := "17"

tokens := strings.Split(LibCVersion(), ".")
if tokens[1] < "17" {
t.Skipf("Skipping error tests. libc version too old (got: %s.%s, need: 2.%s)",
tokens[0], tokens[1], FixedMinorVersion)
}

tests := [][]string{
{"no salt", ""},
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/amoghe/go-crypt

go 1.13
14 changes: 0 additions & 14 deletions version.go

This file was deleted.