<commit_before>package gossl

/*
#include "openssl/ssl.h"
#include "openssl/err.h"
#include "openssl/stack.h"
extern int get_errno(void);

*/
import "C"
import "unsafe"
import "github.com/shanemhansen/gossl/evp"
import "github.com/shanemhansen/gossl/sslerr"
import "runtime"
import "errors"
import "fmt"
import "time"

var _ = fmt.Println

type Context struct {
    Ctx *C.SSL_CTX
}

func NewContext(method *METHOD) *Context {
    c := &Context{C.SSL_CTX_new(method.method)}
    runtime.SetFinalizer(c, contextFree)
    return c
}
func contextFree(self *Context) {
    C.SSL_CTX_free(self.Ctx)
}

func (self *Context) UsePrivateKey(key *evp.PKey) error {
    if int(C.SSL_CTX_use_PrivateKey(self.Ctx, (*C.EVP_PKEY)(unsafe.Pointer(key.PKey)))) != 1 {
        return errors.New("problem loading key " + sslerr.SSLErrorMessage())
    }
    return nil
}

func (self *Context) UseCertificate(cert *Certificate) error {

    if int(C.SSL_CTX_use_certificate(self.Ctx, (*C.X509)(unsafe.Pointer(cert.X509)))) != 1 {
        return errors.New("problem loading cert " + sslerr.SSLErrorMessage())
    }
    return nil
}

func (self *Context) UsePSKIdentityHint(hint string) int {
    return int(C.SSL_CTX_use_psk_identity_hint(self.Ctx, C.CString(hint)))
}

func (self *Context) SetAppData(data unsafe.Pointer) {
    C.SSL_CTX_set_ex_data(self.Ctx, 0, data)
}
func (self *Context) GetAppData() unsafe.Pointer {
    return C.SSL_CTX_get_ex_data(self.Ctx, 0)
}
func (self *Context) Ctrl(op int, op2 int, data unsafe.Pointer) int {
    return int(C.SSL_CTX_ctrl(self.Ctx, C.int(op), C.long(op2), data))
}
func (self *Context) SetCipherList(list string) int {
    return int(C.SSL_CTX_set_cipher_list(self.Ctx, C.CString(list)))
}
func (self *Context) SetTimeout(t time.Time) {
    C.SSL_CTX_set_timeout(self.Ctx, C.long(t.Unix()))
}
func (self *Context) GetTimeout() time.Time {
    return time.Unix(int64(C.SSL_CTX_get_timeout(self.Ctx)), 0)
}
func (self *Context) GetCertStore() *X509Store {
    return &X509Store{Store: C.SSL_CTX_get_cert_store(self.Ctx)}
}
func (self *Context) SetCertStore(store *X509Store) {
    C.SSL_CTX_set_cert_store(self.Ctx, store.Store)
}
func (self *Context) FlushSessions(t time.Time) {
    C.SSL_CTX_flush_sessions(self.Ctx, C.long(t.Unix()))
}
func (self *Context) UseRSAPrivateKeyFile(file string, filetype int) error {
    ret := int(C.SSL_CTX_use_RSAPrivateKey_file(self.Ctx,
        C.CString(file), C.int(filetype)))
    if ret != 1 {
        return errors.New(sslerr.SSLErrorMessage())
    }
    return nil

}
func (self *Context) SetOptions(options int) {
    self.Ctrl(CTRL_OPTIONS, options, nil)
}
func (self *Context) GetOptions() int {
    return int(self.Ctrl(CTRL_OPTIONS, 0, nil))
}
func (self *Context) UsePrivateKeyFile(file string, filetype int) error {
    ret := int(C.SSL_CTX_use_PrivateKey_file(self.Ctx,
        C.CString(file), C.int(filetype)))
    if ret != 1 {
        return errors.New(sslerr.SSLErrorMessage())
    }
    return nil

}
func (self *Context) UseCertificateFile(file string, filetype int) error {
    ret := int(C.SSL_CTX_use_certificate_file(self.Ctx,
        C.CString(file), C.int(filetype)))
    if ret != 1 {
        return errors.New(sslerr.SSLErrorMessage())
    }
    return nil<commit_msg>fix the CTRL_OPTIONS<commit_after>package gossl

/*
#include "openssl/ssl.h"
#include "openssl/err.h"
#include "openssl/stack.h"
extern int get_errno(void);

*/
import "C"
import "unsafe"
import "github.com/shanemhansen/gossl/evp"
import "github.com/shanemhansen/gossl/sslerr"
import "runtime"
import "errors"
import "fmt"
import "time"

var _ = fmt.Println

type Context struct {
    Ctx *C.SSL_CTX
}

func NewContext(method *METHOD) *Context {
    c := &Context{C.SSL_CTX_new(method.method)}
    runtime.SetFinalizer(c, contextFree)
    return c
}
func contextFree(self *Context) {
    C.SSL_CTX_free(self.Ctx)
}

func (self *Context) UsePrivateKey(key *evp.PKey) error {
    if int(C.SSL_CTX_use_PrivateKey(self.Ctx, (*C.EVP_PKEY)(unsafe.Pointer(key.PKey)))) != 1 {
        return errors.New("problem loading key " + sslerr.SSLErrorMessage())
    }
    return nil
}

func (self *Context) UseCertificate(cert *Certificate) error {

    if int(C.SSL_CTX_use_certificate(self.Ctx, (*C.X509)(unsafe.Pointer(cert.X509)))) != 1 {
        return errors.New("problem loading cert " + sslerr.SSLErrorMessage())
    }
    return nil
}

func (self *Context) UsePSKIdentityHint(hint string) int {
    return int(C.SSL_CTX_use_psk_identity_hint(self.Ctx, C.CString(hint)))
}

func (self *Context) SetAppData(data unsafe.Pointer) {
    C.SSL_CTX_set_ex_data(self.Ctx, 0, data)
}
func (self *Context) GetAppData() unsafe.Pointer {
    return C.SSL_CTX_get_ex_data(self.Ctx, 0)
}
func (self *Context) Ctrl(op int, op2 int, data unsafe.Pointer) int {
    return int(C.SSL_CTX_ctrl(self.Ctx, C.int(op), C.long(op2), data))
}
func (self *Context) SetCipherList(list string) int {
    return int(C.SSL_CTX_set_cipher_list(self.Ctx, C.CString(list)))
}
func (self *Context) SetTimeout(t time.Time) {
    C.SSL_CTX_set_timeout(self.Ctx, C.long(t.Unix()))
}
func (self *Context) GetTimeout() time.Time {
    return time.Unix(int64(C.SSL_CTX_get_timeout(self.Ctx)), 0)
}
func (self *Context) GetCertStore() *X509Store {
    return &X509Store{Store: C.SSL_CTX_get_cert_store(self.Ctx)}
}
func (self *Context) SetCertStore(store *X509Store) {
    C.SSL_CTX_set_cert_store(self.Ctx, store.Store)
}
func (self *Context) FlushSessions(t time.Time) {
    C.SSL_CTX_flush_sessions(self.Ctx, C.long(t.Unix()))
}
func (self *Context) UseRSAPrivateKeyFile(file string, filetype int) error {
    ret := int(C.SSL_CTX_use_RSAPrivateKey_file(self.Ctx,
        C.CString(file), C.int(filetype)))
    if ret != 1 {
        return errors.New(sslerr.SSLErrorMessage())
    }
    return nil

}
func (self *Context) SetOptions(options int) {
    self.Ctrl(C.SSL_CTRL_OPTIONS, options, nil)
}
func (self *Context) GetOptions() int {
    return int(self.Ctrl(C.SSL_CTRL_OPTIONS, 0, nil))
}
func (self *Context) UsePrivateKeyFile(file string, filetype int) error {
    ret := int(C.SSL_CTX_use_PrivateKey_file(self.Ctx,
        C.CString(file), C.int(filetype)))
    if ret != 1 {
        return errors.New(sslerr.SSLErrorMessage())
    }
    return nil

}
func (self *Context) UseCertificateFile(file string, filetype int) error {
    ret := int(C.SSL_CTX_use_certificate_file(self.Ctx,
        C.CString(file), C.int(filetype)))
    if ret != 1 {
        return errors.New(sslerr.SSLErrorMessage())
    }
    return nil
{'fraction_non_alphanumeric': 0.14073734128805263, 'fraction_numerical': 0.008566620774055378, 'mean_word_length': 4.27683615819209, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4168216', 'n_tokens_mistral': 2498, 'n_tokens_neox': 2450, 'n_words': 485}