-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harden KeyContent against different line-delimiters
- Loading branch information
1 parent
7232d34
commit 120feef
Showing
5 changed files
with
135 additions
and
19 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
44 changes: 44 additions & 0 deletions
44
...s/src/org/eclipse/passage/lic/net/tests/io/KeyKeeperWithOppositeLineDelimiterFactory.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,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IILS mbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IILS mbH (Hannes Wellmann) - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.net.tests.io; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.io.KeyKeeper; | ||
import org.eclipse.passage.lic.base.io.FileKeyKeeper; | ||
|
||
final class KeyKeeperWithOppositeLineDelimiterFactory extends TestKeyKeeper { | ||
|
||
@Override | ||
public final KeyKeeper get() throws LicensingException, IOException { | ||
Path file = SafePayloadTest.folder.newFile("key.pub").toPath(); //$NON-NLS-1$ | ||
byte[] content = publicKeyContent(); | ||
Files.write(file, content); | ||
return new FileKeyKeeper(file); | ||
} | ||
|
||
private byte[] publicKeyContent() throws IOException { | ||
return Files.lines(publicKey()) // | ||
.collect(Collectors.joining(oppositeLineSeparator())) // | ||
.getBytes(StandardCharsets.UTF_8); | ||
} | ||
|
||
private String oppositeLineSeparator() { | ||
return "\r\n".equals(System.lineSeparator()) ? "\n" : "\r\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...assage.lic.net.tests/src/org/eclipse/passage/lic/net/tests/io/SimpleKeyKeeperFactory.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,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IILS mbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IILS mbH (Hannes Wellmann) - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.net.tests.io; | ||
|
||
import java.io.IOException; | ||
|
||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.io.KeyKeeper; | ||
import org.eclipse.passage.lic.base.io.FileKeyKeeper; | ||
|
||
final class SimpleKeyKeeperFactory extends TestKeyKeeper { | ||
|
||
@Override | ||
public final KeyKeeper get() throws LicensingException, IOException { | ||
return new FileKeyKeeper(publicKey()); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...eclipse.passage.lic.net.tests/src/org/eclipse/passage/lic/net/tests/io/TestKeyKeeper.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,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IILS mbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IILS mbH (Hannes Wellmann) - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.net.tests.io; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.io.KeyKeeper; | ||
|
||
abstract class TestKeyKeeper { | ||
|
||
protected abstract KeyKeeper get() throws LicensingException, IOException; | ||
|
||
protected final Path publicKey() { | ||
return Paths.get("resource").resolve("io").resolve("key.pub"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | ||
} | ||
} |