Package com.microej.crypto.test.util
Class OffsetAssertions
- java.lang.Object
-
- com.microej.crypto.test.util.OffsetAssertions
-
public final class OffsetAssertions extends java.lang.ObjectBuffers and assertions for the operations that take a byte-array offset, exercised at a non-zero offset.Every offset the abstraction layer receives is zero in the rest of the suite, so a backend that drops an
+ offsetproduces the right answer everywhere and is never caught. A case built on this class asserts three things: that the result lands at the requested offset, that it is the expected value, and that the bytes around it are untouched. The last one is what a dropped output offset breaks. The decoy bytes placed before every input are what a dropped input offset breaks, and the ones placed after it are what an ignored input length breaks.
-
-
Field Summary
Fields Modifier and Type Field Description static intINPUT_OFFSETThe offset at which the payload starts in every input array.static intOUTPUT_OFFSETThe offset at which every result is asked to land.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertResultAt(java.lang.String label, byte[] output, int offset, byte[] expected)Asserts that the expected result sits at the given offset of the output, and that every byte before the offset and every byte past the result still holds the canary.static voidassertUntouchedBefore(java.lang.String label, byte[] output, int offset)Asserts that every byte before the given offset still holds the canary.static voidassertUntouchedFrom(java.lang.String label, byte[] output, int from)Asserts that every byte from the given index to the end of the output still holds the canary.static byte[]canaryFilled(int length)Returns an array of the given length filled with the canary.static byte[]outputFor(int resultLength)Returns a canary-filled output with room for a result of the given length atOUTPUT_OFFSETand slack past it.static byte[]resultAt(byte[] output, int offset, int length)Copies a result out of an output array.static byte[]withDecoysAround(byte[] payload)Surrounds the given bytes with decoy bytes, so that an operation reading from offset zero, or reading to the end of the array, processes something different rather than the same thing.
-
-
-
Field Detail
-
INPUT_OFFSET
public static final int INPUT_OFFSET
The offset at which the payload starts in every input array.- See Also:
- Constant Field Values
-
OUTPUT_OFFSET
public static final int OUTPUT_OFFSET
The offset at which every result is asked to land.- See Also:
- Constant Field Values
-
-
Method Detail
-
withDecoysAround
public static byte[] withDecoysAround(byte[] payload)
Surrounds the given bytes with decoy bytes, so that an operation reading from offset zero, or reading to the end of the array, processes something different rather than the same thing.- Parameters:
payload- the bytes the operation is meant to read- Returns:
- a new array holding the payload at
INPUT_OFFSET, with decoy bytes before and after it
-
outputFor
public static byte[] outputFor(int resultLength)
Returns a canary-filled output with room for a result of the given length atOUTPUT_OFFSETand slack past it.- Parameters:
resultLength- the room the operation requires for its result- Returns:
- a new canary-filled array
-
canaryFilled
public static byte[] canaryFilled(int length)
Returns an array of the given length filled with the canary.- Parameters:
length- the length of the array- Returns:
- a new canary-filled array
-
resultAt
public static byte[] resultAt(byte[] output, int offset, int length)Copies a result out of an output array.- Parameters:
output- the array the operation wrote intooffset- the offset at which the result startslength- the length of the result- Returns:
- a new array holding the result
-
assertResultAt
public static void assertResultAt(java.lang.String label, byte[] output, int offset, byte[] expected)Asserts that the expected result sits at the given offset of the output, and that every byte before the offset and every byte past the result still holds the canary.- Parameters:
label- the operation, for the assertion messagesoutput- the array the operation wrote intooffset- the offset the operation was asked to write atexpected- the expected result
-
assertUntouchedBefore
public static void assertUntouchedBefore(java.lang.String label, byte[] output, int offset)Asserts that every byte before the given offset still holds the canary.- Parameters:
label- the operation, for the assertion messagesoutput- the array the operation wrote intooffset- the offset the operation was asked to write at
-
assertUntouchedFrom
public static void assertUntouchedFrom(java.lang.String label, byte[] output, int from)Asserts that every byte from the given index to the end of the output still holds the canary.- Parameters:
label- the operation, for the assertion messagesoutput- the array the operation wrote intofrom- the first index past the result
-
-