-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5168f6d
commit 487852c
Showing
13 changed files
with
545 additions
and
353 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/xades4j/production/DefaultElementIdGeneratorFactory.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,31 @@ | ||
/* | ||
* XAdES4j - A Java library for generation and verification of XAdES signatures. | ||
* Copyright (C) 2024 Luis Goncalves. | ||
* | ||
* XAdES4j is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or any later version. | ||
* | ||
* XAdES4j 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 Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along | ||
* with XAdES4j. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package xades4j.production; | ||
|
||
import java.util.UUID; | ||
|
||
final class DefaultElementIdGeneratorFactory implements ElementIdGeneratorFactory | ||
{ | ||
@Override | ||
public ElementIdGenerator create() | ||
{ | ||
return (namespace, name) -> { | ||
return name.toLowerCase() + "-" + UUID.randomUUID(); | ||
}; | ||
} | ||
} |
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
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,57 @@ | ||
/* | ||
* XAdES4j - A Java library for generation and verification of XAdES signatures. | ||
* Copyright (C) 2024 Luis Goncalves. | ||
* | ||
* XAdES4j is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or any later version. | ||
* | ||
* XAdES4j 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 Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along | ||
* with XAdES4j. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package xades4j.production; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Generates IDs for XML elements in a given signing operation. | ||
*/ | ||
public interface ElementIdGenerator | ||
{ | ||
/** | ||
* Generate an ID for an XML element. | ||
* | ||
* @param namespace the element namespace | ||
* @param name the element name | ||
* @return the ID | ||
*/ | ||
String generateId(String namespace, String name); | ||
|
||
/** | ||
* Gets a {@link ElementIdGenerator} that uses a UUID for each requested ID. | ||
*/ | ||
static ElementIdGenerator uuid() | ||
{ | ||
return uuid(null, null); | ||
} | ||
|
||
/** | ||
* Gets a {@link ElementIdGenerator} that uses a UUID for each requested ID, optionally using a constant prefix | ||
* and/or suffix. | ||
* | ||
* @param prefix the ID prefix (may be null) | ||
* @param suffix the ID suffix (may be null) | ||
*/ | ||
static ElementIdGenerator uuid(String prefix, String suffix) | ||
{ | ||
final String p = prefix == null ? "" : prefix; | ||
final String s = suffix == null ? "" : suffix; | ||
return (ns, n) -> p + UUID.randomUUID() + s; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/xades4j/production/ElementIdGeneratorFactory.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,55 @@ | ||
/* | ||
* XAdES4j - A Java library for generation and verification of XAdES signatures. | ||
* Copyright (C) 2024 Luis Goncalves. | ||
* | ||
* XAdES4j is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or any later version. | ||
* | ||
* XAdES4j 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 Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along | ||
* with XAdES4j. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package xades4j.production; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* A factory of {@link ElementIdGenerator}. | ||
*/ | ||
public interface ElementIdGeneratorFactory | ||
{ | ||
/** | ||
* Create a new {@link ElementIdGenerator}. This method is invoked once for each signing operation and the returned | ||
* instance is used to obtain element IDs during that operation. This allows for scenarios where all the element IDs | ||
* share a common base. | ||
* | ||
* @return the ID generator | ||
*/ | ||
ElementIdGenerator create(); | ||
|
||
/** | ||
* Gets a {@link ElementIdGeneratorFactory} that uses a UUID for each requested ID. | ||
*/ | ||
static ElementIdGeneratorFactory uuid() | ||
{ | ||
return ElementIdGenerator::uuid; | ||
} | ||
|
||
/** | ||
* Gets a {@link ElementIdGeneratorFactory} that uses a UUID for each requested ID, optionally using a constant | ||
* prefix and/or suffix. | ||
* | ||
* @param prefix the ID prefix (may be null) | ||
* @param suffix the ID suffix (may be null) | ||
*/ | ||
static ElementIdGeneratorFactory uuid(String prefix, String suffix) | ||
{ | ||
return () -> ElementIdGenerator.uuid(prefix, suffix); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.