Simplified lifecycle (initialized, disposed) checks.

This commit is contained in:
antiduh
2014-07-01 18:36:16 +00:00
parent 306fe44cc1
commit b742dbbff4

View File

@@ -36,6 +36,7 @@ namespace NSspi.Contexts
{ {
get get
{ {
CheckLifecycle();
return QueryContextString( ContextQueryAttrib.Authority ); return QueryContextString( ContextQueryAttrib.Authority );
} }
} }
@@ -44,6 +45,7 @@ namespace NSspi.Contexts
{ {
get get
{ {
CheckLifecycle();
return QueryContextString( ContextQueryAttrib.Names ); return QueryContextString( ContextQueryAttrib.Names );
} }
} }
@@ -106,14 +108,7 @@ namespace NSspi.Contexts
SecurityStatus status = SecurityStatus.InvalidHandle; SecurityStatus status = SecurityStatus.InvalidHandle;
byte[] result; byte[] result;
if ( this.Initialized == false ) CheckLifecycle();
{
throw new InvalidOperationException( "The context is not fully formed." );
}
else if( this.Disposed )
{
throw new ObjectDisposedException( "Context" );
}
sizes = QueryBufferSizes(); sizes = QueryBufferSizes();
@@ -186,14 +181,7 @@ namespace NSspi.Contexts
int dataLength; int dataLength;
int paddingLength; int paddingLength;
if ( this.Initialized == false ) CheckLifecycle();
{
throw new InvalidOperationException( "The context is not fully formed." );
}
else if( this.Disposed )
{
throw new ObjectDisposedException( "Context" );
}
sizes = QueryBufferSizes(); sizes = QueryBufferSizes();
@@ -284,10 +272,7 @@ namespace NSspi.Contexts
SecureBuffer signatureBuffer; SecureBuffer signatureBuffer;
SecureBufferAdapter adapter; SecureBufferAdapter adapter;
if ( this.Initialized == false ) CheckLifecycle();
{
throw new InvalidOperationException( "The context is not fully formed" );
}
sizes = QueryBufferSizes(); sizes = QueryBufferSizes();
@@ -346,10 +331,7 @@ namespace NSspi.Contexts
SecureBuffer signatureBuffer; SecureBuffer signatureBuffer;
SecureBufferAdapter adapter; SecureBufferAdapter adapter;
if ( this.Initialized == false ) CheckLifecycle();
{
throw new InvalidOperationException( "The context is not fully formed." );
}
sizes = QueryBufferSizes(); sizes = QueryBufferSizes();
@@ -509,5 +491,17 @@ namespace NSspi.Contexts
return result; return result;
} }
private void CheckLifecycle()
{
if( this.Initialized == false )
{
throw new InvalidOperationException( "The context is not yet fully formed." );
}
else if( this.Disposed )
{
throw new ObjectDisposedException( "Context" );
}
}
} }
} }