From b742dbbff4a64a2601fad6c33842f63662093ea6 Mon Sep 17 00:00:00 2001 From: antiduh Date: Tue, 1 Jul 2014 18:36:16 +0000 Subject: [PATCH] Simplified lifecycle (initialized, disposed) checks. --- NSspi/Contexts/Context.cs | 42 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/NSspi/Contexts/Context.cs b/NSspi/Contexts/Context.cs index a955a1f..9d56176 100644 --- a/NSspi/Contexts/Context.cs +++ b/NSspi/Contexts/Context.cs @@ -36,6 +36,7 @@ namespace NSspi.Contexts { get { + CheckLifecycle(); return QueryContextString( ContextQueryAttrib.Authority ); } } @@ -44,6 +45,7 @@ namespace NSspi.Contexts { get { + CheckLifecycle(); return QueryContextString( ContextQueryAttrib.Names ); } } @@ -106,14 +108,7 @@ namespace NSspi.Contexts SecurityStatus status = SecurityStatus.InvalidHandle; byte[] result; - if ( this.Initialized == false ) - { - throw new InvalidOperationException( "The context is not fully formed." ); - } - else if( this.Disposed ) - { - throw new ObjectDisposedException( "Context" ); - } + CheckLifecycle(); sizes = QueryBufferSizes(); @@ -186,14 +181,7 @@ namespace NSspi.Contexts int dataLength; int paddingLength; - if ( this.Initialized == false ) - { - throw new InvalidOperationException( "The context is not fully formed." ); - } - else if( this.Disposed ) - { - throw new ObjectDisposedException( "Context" ); - } + CheckLifecycle(); sizes = QueryBufferSizes(); @@ -284,10 +272,7 @@ namespace NSspi.Contexts SecureBuffer signatureBuffer; SecureBufferAdapter adapter; - if ( this.Initialized == false ) - { - throw new InvalidOperationException( "The context is not fully formed" ); - } + CheckLifecycle(); sizes = QueryBufferSizes(); @@ -346,10 +331,7 @@ namespace NSspi.Contexts SecureBuffer signatureBuffer; SecureBufferAdapter adapter; - if ( this.Initialized == false ) - { - throw new InvalidOperationException( "The context is not fully formed." ); - } + CheckLifecycle(); sizes = QueryBufferSizes(); @@ -509,5 +491,17 @@ namespace NSspi.Contexts 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" ); + } + } } }