This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add various Base encoding functions (#190)
- Loading branch information
Showing
14 changed files
with
566 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base16Decode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base16Decode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base16_decode"; | ||
private static final String ENCODING_NAME = "base16"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base16(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return new String(encoding.decode(value), StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base16Encode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base16Encode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base16_encode"; | ||
private static final String ENCODING_NAME = "base16"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base16(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return encoding.encode(value.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base32Decode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base32Decode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base32_decode"; | ||
private static final String ENCODING_NAME = "base32"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base32Hex(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return new String(encoding.decode(value), StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base32Encode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base32Encode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base32_encode"; | ||
private static final String ENCODING_NAME = "base32"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base32Hex(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return encoding.encode(value.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base32HumanDecode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base32HumanDecode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base32human_decode"; | ||
private static final String ENCODING_NAME = "base32 (human-friendly)"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base32(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return new String(encoding.decode(value), StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base32HumanEncode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base32HumanEncode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base32human_encode"; | ||
private static final String ENCODING_NAME = "base32 (human-friendly)"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base32(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return encoding.encode(value.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base64Decode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base64Decode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base64_decode"; | ||
private static final String ENCODING_NAME = "base64"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base64(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return new String(encoding.decode(value), StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/encoding/Base64Encode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.functions.encoding; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Base64Encode extends BaseEncodingSingleArgStringFunction { | ||
public static final String NAME = "base64_encode"; | ||
private static final String ENCODING_NAME = "base64"; | ||
|
||
@Override | ||
protected String getEncodedValue(String value, boolean omitPadding) { | ||
BaseEncoding encoding = BaseEncoding.base64(); | ||
encoding = omitPadding ? encoding.omitPadding() : encoding; | ||
|
||
return encoding.encode(value.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
@Override | ||
protected String getEncodingName() { | ||
return ENCODING_NAME; | ||
} | ||
|
||
protected String getName() { | ||
return NAME; | ||
} | ||
} |
Oops, something went wrong.