Class SensitiveResult
java.lang.Object
javacardx.security.SensitiveResult
The
SensitiveResult class provides methods for asserting results of
sensitive functions. Sensitive methods of the Java Card API (refer to the
See Also section below) store their
results so that callers of these methods can assert their return values. If
such a method returns abnormally with an exception then the stored result is
tagged as Unassigned and any subsequent assertion of the result will
fail.
The stored result is unaffected by context switches; especially,
the stored result from an API method called by the method of a
Shareable Interface Object is not automatically reset upon switching back to the context
of the caller; it is the responsibility of the Shareable Interface Object
implementation to reset the stored result if necessary using the reset
method.
Upon entering any of the Applet entry point methods the stored result is tagged as Unassigned.
The sample code below illustrates the use of the SensitiveResult
class:
try {
boolean res = signature.verify(...);
if (res) {
SensitiveResult.assertTrue();
// Grant service
} else {
SensitiveResult.assertFalse();
// Deny service
}
} finally {
SensitiveResult.reset();
}
Note that results from Java Card API methods yielding a byte result
are stored as short after conversion (with sign-extension).
- Since:
- 3.0.5
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertEquals(short val) Asserts the stored result to be ashortvalue equal to the providedshortvalue.static voidassertEquals(Object obj) Asserts the stored result to be an object reference equal to the provided object reference.static voidAsserts the stored result to be abooleanvalue equal tofalse.static voidassertGreaterThan(short val) Asserts the stored result to be ashortvalue strictly greater than the providedshortvalue.static voidassertLessThan(short val) Asserts the stored result to be ashortvalue strictly less than the providedshortvalue.static voidAsserts the stored result to be ashortvalue strictly negative.static voidAsserts the stored result to be ashortvalue strictly positive.static voidAsserts the stored result to be abooleanvalue equal totrue.static voidAsserts the stored result to be ashortvalue equal to zero.static voidreset()Resets the stored result.
-
Method Details
-
assertEquals
Asserts the stored result to be an object reference equal to the provided object reference. This method throws an exception if and only if the stored result referenceresand the provided object referenceobjdo not refer to the same object or are not bothnull; in other words(res == obj)evaluates tofalse.- Parameters:
obj- The object reference to compare with the stored result.- Throws:
SecurityException- if the provided object reference is not equal to that of the stored result.
-
assertTrue
Asserts the stored result to be abooleanvalue equal totrue.- Throws:
SecurityException- if the stored result is not set totrue.
-
assertFalse
Asserts the stored result to be abooleanvalue equal tofalse.- Throws:
SecurityException- if the stored result is not set tofalse.
-
assertNegative
Asserts the stored result to be ashortvalue strictly negative. A call to this method is semantically equivalent to a call toassertLessThan(short)with parameter0.- Throws:
SecurityException- if the stored result is not negative.
-
assertPositive
Asserts the stored result to be ashortvalue strictly positive. A call to this method is semantically equivalent to a call toassertGreaterThan(short)with parameter0.- Throws:
SecurityException- if the stored result is not positive.
-
assertZero
Asserts the stored result to be ashortvalue equal to zero. A call to this method is semantically equivalent to a call toassertEquals(short)with parameter0.- Throws:
SecurityException- if the stored result is not zero.
-
assertEquals
Asserts the stored result to be ashortvalue equal to the providedshortvalue.- Parameters:
val- Theshortvalue to compare with the stored result.- Throws:
SecurityException- if the provided value is not equal to that of the stored result.
-
assertGreaterThan
Asserts the stored result to be ashortvalue strictly greater than the providedshortvalue.- Parameters:
val- Theshortvalue to compare with the stored result.- Throws:
SecurityException- if the provided value is not greater than that of the stored result.
-
assertLessThan
Asserts the stored result to be ashortvalue strictly less than the providedshortvalue.- Parameters:
val- Theshortvalue to compare with the stored result.- Throws:
SecurityException- if the provided value is not less than that of the stored result.
-
reset
public static void reset()Resets the stored result. The stored result is tagged as Unassigned and any subsequent assertion of the result will fail.
-