<commit_before>#include "gsspp/gsscontext.h"
#include "gsspp/gssbuffer.h"
#include "gsspp/gssname.h"
#include "gsspp/gsscredential.h"
#include "gsspp/gssmech.h"
#include "gsspp/gssexception.h"
#include <gssapi.h>


GSSContext::GSSContext( const GSSBuffer& buff )
{
	import_context( buff );
}

void GSSContext::clear()
{
	OM_uint32 x;
	gss_delete_sec_context( &x, &_context, GSS_C_NO_BUFFER );
}

bool GSSContext::initialize( GSSBuffer& input, const GSSName& target, const Flags& flags, GSSCredential cred, GSSMech mech, OM_uint32 time, gss_channel_bindings_t bindings )
{
	GSSBuffer recv_tok, send_tok;
	OM_uint32 maj_stat, min_stat, ret_flags;

	maj_stat = gss_init_sec_context(
			&min_stat,
			cred,
			&_context,
			target,
			mech,
			flags,
			time,
			bindings,
			input,
			0,
			send_tok,
			&ret_flags,
			0
	);

	if ( !valid() || ( maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED ) ) {
		throw GSSException( maj_stat, min_stat, "gss_init_sec_context" );
	}

	input.swap( send_tok );

	return maj_stat == GSS_S_CONTINUE_NEEDED;
}
	
void GSSContext::import_context( const GSSBuffer& buff )
{
	OM_uint32 maj, min;
	maj = gss_import_sec_context( &min, const_cast<GSSBuffer&>( buff ), &_context );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_import_sec_context" );
	}
}

GSSBuffer GSSContext::export_context()
{
	OM_uint32 maj, min;
	GSSBuffer exported;
	gss_export_sec_context( &min, &_context, exported );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_export_sec_context" );
	}

	return exported;
}

GSSBuffer GSSContext::get_mic( const GSSBuffer& message, gss_qop_t qop = GSS_C_QOP_DEFAULT ) const
{
	OM_uint32 maj, min;
	GSSBuffer mic;

	maj = gss_get_mic( &min, &_context, qop, message, mic );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_get_mic" );
	}

	return mic;
}

bool GSSContext::verify_mic( const GSSBuffer& message, const GSSBuffer& mic )
{
	OM_uint32 maj, min;
	maj = gss_verify_mic( &min, &_context, message, mic, 0 );

	if ( maj == GSS_S_COMPLETE )
		return true;
	if ( maj == GSS_S_BAD_SIG )
		return false;
	throw GSSException( maj, min, "gss_verify_mic" );
}

GSSBuffer GSSContext::wrap( const GSSBuffer& message, bool encrypt, gss_qop_t qop ) const
{ 
	return wrap( *this, message, encrypt, qop );
}

GSSBuffer GSSContext::wrap( const GSSContext& context, const GSSBuffer& message, bool encrypt, gss_qop_t qop )
{
	OM_uint32 maj, min;
	GSSBuffer wrapped;
	maj = gss_wrap( &min, context, encrypt, qop, const_cast<GSSBuffer&>( message ), 0, wrapped );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_wrap" );
	}

	return wrapped;
}

void GSSContext::wrap_in_place( GSSBuffer& message, bool encrypt, gss_qop_t qop ) const
{
	wrap_in_place( *this, message, encrypt, qop );
}

void GSSContext::wrap_in_place( const GSSContext& context, GSSBuffer& message, bool encrypt, gss_qop_t qop )
{
	GSSBuffer tmp( wrap( context, message, encrypt, qop ) );
	message.swap( tmp );
}

GSSBuffer GSSContext::unwrap( const GSSBuffer& wrapped ) const
{
	return unwrap( *this, wrapped );
}

GSSBuffer GSSContext::unwrap( const GSSContext& context, const GSSBuffer& message )
{
	OM_uint32 maj, min;
	GSSBuffer unwrapped;
	maj = gss_unwrap( &min, context, const_cast<GSSBuffer&>( message ), unwrapped, 0, 0 );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_unwrap" );
	}

	return unwrapped;
}
	
void GSSContext::unwrap_in_place( GSSBuffer& wrapped ) const
{
	unwrap_in_place( *this, wrapped );
}

void GSSContext::unwrap_in_place( const GSSContext& context, GSSBuffer& message )
{
	GSSBuffer tmp( unwrap( context, message ) );
	message.swap( tmp );
}
<commit_msg>fixed compiler errors in gsscontext.cpp<commit_after>#include "gsspp/gsscontext.h"
#include "gsspp/gssbuffer.h"
#include "gsspp/gssname.h"
#include "gsspp/gsscredential.h"
#include "gsspp/gssmech.h"
#include "gsspp/gssexception.h"
#include <gssapi.h>


GSSContext::GSSContext( const GSSBuffer& buff )
{
	import_context( buff );
}

void GSSContext::clear()
{
	OM_uint32 x;
	gss_delete_sec_context( &x, &_context, GSS_C_NO_BUFFER );
}

bool GSSContext::initialize( GSSBuffer& input, const GSSName& target, const Flags& flags, GSSCredential cred, GSSMech mech, OM_uint32 time, gss_channel_bindings_t bindings )
{
	GSSBuffer recv_tok, send_tok;
	OM_uint32 maj_stat, min_stat, ret_flags;

	maj_stat = gss_init_sec_context(
			&min_stat,
			cred,
			&_context,
			target,
			mech,
			flags,
			time,
			bindings,
			input,
			0,
			send_tok,
			&ret_flags,
			0
	);

	if ( !valid() || ( maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED ) ) {
		throw GSSException( maj_stat, min_stat, "gss_init_sec_context" );
	}

	input.swap( send_tok );

	return maj_stat == GSS_S_CONTINUE_NEEDED;
}
	
void GSSContext::import_context( const GSSBuffer& buff )
{
	OM_uint32 maj, min;
	maj = gss_import_sec_context( &min, const_cast<GSSBuffer&>( buff ), &_context );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_import_sec_context" );
	}
}

GSSBuffer GSSContext::export_context()
{
	OM_uint32 maj, min;
	GSSBuffer exported;
	gss_export_sec_context( &min, &_context, exported );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_export_sec_context" );
	}

	return exported;
}

GSSBuffer GSSContext::get_mic( const GSSBuffer& message, gss_qop_t qop ) const
{
	OM_uint32 maj, min;
	GSSBuffer mic;

	maj = gss_get_mic( &min, _context, qop, const_cast<GSSBuffer&>( message ), mic );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_get_mic" );
	}

	return mic;
}

bool GSSContext::verify_mic( const GSSBuffer& message, const GSSBuffer& mic )
{
	OM_uint32 maj, min;
	maj = gss_verify_mic( &min, _context, const_cast<GSSBuffer&>( message ), const_cast<GSSBuffer&>( mic ), 0 );

	if ( maj == GSS_S_COMPLETE )
		return true;
	if ( maj == GSS_S_BAD_SIG )
		return false;
	throw GSSException( maj, min, "gss_verify_mic" );
}

GSSBuffer GSSContext::wrap( const GSSBuffer& message, bool encrypt, gss_qop_t qop ) const
{ 
	return wrap( *this, message, encrypt, qop );
}

GSSBuffer GSSContext::wrap( const GSSContext& context, const GSSBuffer& message, bool encrypt, gss_qop_t qop )
{
	OM_uint32 maj, min;
	GSSBuffer wrapped;
	maj = gss_wrap( &min, context, encrypt, qop, const_cast<GSSBuffer&>( message ), 0, wrapped );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_wrap" );
	}

	return wrapped;
}

void GSSContext::wrap_in_place( GSSBuffer& message, bool encrypt, gss_qop_t qop ) const
{
	wrap_in_place( *this, message, encrypt, qop );
}

void GSSContext::wrap_in_place( const GSSContext& context, GSSBuffer& message, bool encrypt, gss_qop_t qop )
{
	GSSBuffer tmp( wrap( context, message, encrypt, qop ) );
	message.swap( tmp );
}

GSSBuffer GSSContext::unwrap( const GSSBuffer& wrapped ) const
{
	return unwrap( *this, wrapped );
}

GSSBuffer GSSContext::unwrap( const GSSContext& context, const GSSBuffer& message )
{
	OM_uint32 maj, min;
	GSSBuffer unwrapped;
	maj = gss_unwrap( &min, context, const_cast<GSSBuffer&>( message ), unwrapped, 0, 0 );

	if ( maj != GSS_S_COMPLETE )
	{
		throw GSSException( maj, min, "gss_unwrap" );
	}

	return unwrapped;
}
	
void GSSContext::unwrap_in_place( GSSBuffer& wrapped ) const
{
	unwrap_in_place( *this, wrapped );
}

void GSSContext::unwrap_in_place( const GSSContext& context, GSSBuffer& message )
{
	GSSBuffer tmp( unwrap( context, message ) );
	message.swap( tmp );
}

{'fraction_non_alphanumeric': 0.12259871931696906, 'fraction_numerical': 0.0064034151547491995, 'mean_word_length': 4.940570522979398, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '3054330', 'n_tokens_mistral': 3148, 'n_tokens_neox': 3011, 'n_words': 690}