Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to tink-fpe #11

Merged
merged 7 commits into from
Mar 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add constants for some pseudo func names
kschulst committed Mar 13, 2023
commit 282527397ecdedd5c961290e05384f280b11ca74
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@

import static no.ssb.dapla.dlp.pseudo.func.fpe.Alphabets.alphabetNameOf;
import static no.ssb.dapla.dlp.pseudo.func.text.CharacterGroup.*;
import static no.ssb.dlp.pseudo.core.func.PseudoFuncNames.*;

@Slf4j
class PseudoFuncConfigFactory {
@@ -31,13 +32,13 @@ class PseudoFuncConfigFactory {

static {
PSEUDO_CONFIG_PRESETS_MAP.putAll(Maps.uniqueIndex(List.of(
tinkDaeadPseudoFuncConfigPreset("daead"),
tinkFpePseudoFuncConfigPreset("ff31"),
sidMappingPseudoFuncConfigPreset("map-sid"),
redactPseudoFuncConfigPreset("redact"),
fpePseudoFuncConfigPreset("fpe-text", alphabetNameOf(ALPHANUMERIC, WHITESPACE, SYMBOLS)),
fpePseudoFuncConfigPreset("fpe-text_no", alphabetNameOf(ALPHANUMERIC_NO, WHITESPACE, SYMBOLS)),
fpePseudoFuncConfigPreset("fpe-fnr", alphabetNameOf(DIGITS))
tinkDaeadPseudoFuncConfigPreset(DAEAD),
tinkFpePseudoFuncConfigPreset(FF31),
sidMappingPseudoFuncConfigPreset(MAP_SID),
redactPseudoFuncConfigPreset(REDACT),
fpePseudoFuncConfigPreset(FPE + "-text", alphabetNameOf(ALPHANUMERIC, WHITESPACE, SYMBOLS)),
fpePseudoFuncConfigPreset(FPE + "-text_no", alphabetNameOf(ALPHANUMERIC_NO, WHITESPACE, SYMBOLS)),
fpePseudoFuncConfigPreset(FPE + "-fnr", alphabetNameOf(DIGITS))

), PseudoFuncConfigPreset::getFuncName));
}
@@ -74,8 +75,8 @@ private static PseudoFuncConfigPreset tinkFpePseudoFuncConfigPreset(String funcN
}

private static PseudoFuncConfigPreset fpePseudoFuncConfigPreset(String funcName, String alphabet) {
if (!funcName.startsWith("fpe-")) {
throw new IllegalArgumentException("FPE functions must be prefixed with 'fpe-'");
if (!funcName.startsWith(FPE)) {
throw new IllegalArgumentException("Legacy FPE functions must be prefixed with '" + FPE + "'");
}

return PseudoFuncConfigPreset.builder(funcName, FpeFunc.class)
@@ -98,8 +99,8 @@ static PseudoFuncConfigPreset getConfigPreset(PseudoFuncDeclaration funcDecl) {
The alphabet to be used will be deduced from the function name (+ separated string with references to
any already defined CharacterGroup, see no.ssb.dapla.dlp.pseudo.func.fpe.Alphabets)
*/
if (funcName.startsWith("fpe-")) {
String alphabetName = funcDecl.getFuncName().substring(4);
if (funcName.startsWith(FPE + "-")) {
String alphabetName = funcDecl.getFuncName().substring((FPE + "-").length());
log.info("Add dynamic FPE function preset '{}' with alphabet '{}'. Allowed characters: {}",
funcName, alphabetName, new String(Alphabets.fromAlphabetName(alphabetName).availableCharacters()));
preset = fpePseudoFuncConfigPreset(funcName, alphabetName);
16 changes: 16 additions & 0 deletions src/main/java/no/ssb/dlp/pseudo/core/func/PseudoFuncNames.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package no.ssb.dlp.pseudo.core.func;

/**
* Pseudo function name constants
*/
public final class PseudoFuncNames {
private PseudoFuncNames() {
}

public static final String FF31 = "ff31";
public static final String DAEAD = "daead";
public static final String MAP_SID = "map-sid";
public static final String REDACT = "redact";
public static final String FPE = "fpe";

}