Class ValueMaskingUtil

java.lang.Object
dev.blaauwendraad.masker.json.util.ValueMaskingUtil

public final class ValueMaskingUtil extends Object
Class containing utility methods to replace a particular target value with a mask. This can be used for length obfuscation and ignoring escaping characters in string values.
  • Method Details

    • replaceTargetValueWith

      public static void replaceTargetValueWith(MaskingState maskingState, int targetValueLength, byte[] mask, int maskRepeat)
      Replaces a target value (byte slice) with a mask byte. If lengths of both target value and mask are equal, the replacement is done in-place, otherwise a replacement operation is recorded to be performed as a batch using flushReplacementOperations(dev.blaauwendraad.masker.json.MaskingState).
      Parameters:
      maskingState - the masking state
      targetValueLength - the length of the target value slice.
      mask - the bytes to replace the value slice with.
    • flushReplacementOperations

      public static void flushReplacementOperations(MaskingState maskingState)
      Performs all replacement operations to the message array, must be called at the end of the replacements.

      For every operation that required resizing of the original array, to avoid copying the array multiple times, those operations were stored in a list and can be performed in one go, thus resizing the array only once.

      Replacement operation is only recorded if the length of the target value is different from the length of the mask, otherwise the replacement must have been done in-place.

      Parameters:
      maskingState - the current state of the JsonMasker instance.