-
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 5b4c4e6
Showing
5 changed files
with
128 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
45 changes: 45 additions & 0 deletions
45
...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,45 @@ | ||
/******************************************************************************* | ||
* 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 java.util.stream.Stream; | ||
|
||
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 TestKeyKeeperFactory { | ||
|
||
@Override | ||
public KeyKeeper get() throws LicensingException, IOException { | ||
Path file = SafePayloadTest.folder.newFile("key.pub").toPath(); //$NON-NLS-1$ | ||
byte[] content = publicKeyLines() // | ||
.collect(Collectors.joining(oppositeLineSeparator())) // | ||
.getBytes(StandardCharsets.UTF_8); | ||
Files.write(file, content); | ||
return new FileKeyKeeper(file); | ||
} | ||
|
||
private Stream<String> publicKeyLines() throws IOException { | ||
return Files.lines(publicKey()); | ||
} | ||
|
||
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
17 changes: 17 additions & 0 deletions
17
...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,17 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
class SimpleKeyKeeperFactory extends TestKeyKeeperFactory { | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
....passage.lic.net.tests/src/org/eclipse/passage/lic/net/tests/io/TestKeyKeeperFactory.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,32 @@ | ||
/******************************************************************************* | ||
* 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; | ||
import org.eclipse.passage.lic.base.io.FileKeyKeeper; | ||
|
||
abstract class TestKeyKeeperFactory { | ||
|
||
public KeyKeeper get() throws LicensingException, IOException { | ||
return new FileKeyKeeper(publicKey()); | ||
} | ||
|
||
protected Path publicKey() { | ||
return Paths.get("resource").resolve("io").resolve("key.pub"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | ||
} | ||
} |