public void ConstructorLibraryPathTest() { // Existing PKCS#11 library using (Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, _hashAlgorithm)) Assert.IsTrue(pkcs11RsaSignature != null); // Non-existing PKCS#11 library try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_incorrectString, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is UnmanagedException); } // Unspecified PKCS#11 library try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(null, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentNullException); } }
public void ConstructorHashAlgorihtmTest() { // Defined hashAlgorihtm using (Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, _hashAlgorithm)) Assert.IsTrue(pkcs11RsaSignature != null); // Undefined hashAlgorihtm try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, (HashAlgorithm)123456); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); } }
public void ConstructorPinTest() { // Correct PIN using (Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, _hashAlgorithm)) Assert.IsTrue(pkcs11RsaSignature != null); // Incorrect PIN try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _incorrectString, _ckaLabel, _ckaId, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is Pkcs11Exception); Assert.IsTrue(((Pkcs11Exception)ex).RV == CKR.CKR_PIN_INCORRECT); } }
public void ConstructorCkaLabelAndIdTest() { // Both ckaLabel and ckaId specified using (Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _ckaId, _hashAlgorithm)) Assert.IsTrue(pkcs11RsaSignature != null); // Only ckaLabel specified using (Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, null, _hashAlgorithm)) Assert.IsTrue(pkcs11RsaSignature != null); // Only ckaId specified using (Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, null, _ckaId, _hashAlgorithm)) Assert.IsTrue(pkcs11RsaSignature != null); // Both ckaLabel and ckaId unspecified try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, null, null, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); } // Both ckaLabel and ckaId incorrect try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _incorrectString, _incorrectString, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ObjectNotFoundException); } // Only ckaLabel incorrect try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _incorrectString, _ckaId, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ObjectNotFoundException); } // Only ckaId incorrect try { Pkcs11RsaSignature pkcs11RsaSignature = new Pkcs11RsaSignature(_libraryPath, _tokenSerial, _tokenLabel, _pin, _ckaLabel, _incorrectString, _hashAlgorithm); pkcs11RsaSignature.Dispose(); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ObjectNotFoundException); } }