Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Add various Base encoding functions (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschi authored and bernd committed Sep 11, 2017
1 parent 3a7905c commit 125a754
Show file tree
Hide file tree
Showing 14 changed files with 566 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.MapBinder;

import org.graylog.plugins.pipelineprocessor.ast.functions.Function;
import org.graylog.plugins.pipelineprocessor.functions.conversion.BooleanConversion;
import org.graylog.plugins.pipelineprocessor.functions.conversion.DoubleConversion;
Expand All @@ -41,6 +40,16 @@
import org.graylog.plugins.pipelineprocessor.functions.dates.periods.Weeks;
import org.graylog.plugins.pipelineprocessor.functions.dates.periods.Years;
import org.graylog.plugins.pipelineprocessor.functions.debug.Debug;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base16Decode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base16Encode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base32Decode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base32Encode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base32HumanDecode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base32HumanEncode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base64Decode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base64Encode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base64UrlDecode;
import org.graylog.plugins.pipelineprocessor.functions.encoding.Base64UrlEncode;
import org.graylog.plugins.pipelineprocessor.functions.hashing.CRC32;
import org.graylog.plugins.pipelineprocessor.functions.hashing.CRC32C;
import org.graylog.plugins.pipelineprocessor.functions.hashing.MD5;
Expand Down Expand Up @@ -158,6 +167,16 @@ protected void configure() {
addMessageProcessorFunction(SHA256.NAME, SHA256.class);
addMessageProcessorFunction(SHA512.NAME, SHA512.class);

// encoding
addMessageProcessorFunction(Base16Encode.NAME, Base16Encode.class);
addMessageProcessorFunction(Base16Decode.NAME, Base16Decode.class);
addMessageProcessorFunction(Base32Encode.NAME, Base32Encode.class);
addMessageProcessorFunction(Base32Decode.NAME, Base32Decode.class);
addMessageProcessorFunction(Base32HumanEncode.NAME, Base32HumanEncode.class);
addMessageProcessorFunction(Base32HumanDecode.NAME, Base32HumanDecode.class);
addMessageProcessorFunction(Base64UrlEncode.NAME, Base64UrlEncode.class);
addMessageProcessorFunction(Base64UrlDecode.NAME, Base64UrlDecode.class);

// ip handling
addMessageProcessorFunction(CidrMatch.NAME, CidrMatch.class);
addMessageProcessorFunction(IpAddressConversion.NAME, IpAddressConversion.class);
Expand Down
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit 125a754

Please sign in to comment.