Skip to content

Commit c147b9e

Browse files
authored
Merge pull request #99 from filip26/feat/410
4.1.0
2 parents db1c361 + a15f99d commit c147b9e

5 files changed

Lines changed: 98 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A Java implementation of [Multibase](https://w3c-ccg.github.io/multibase/).
44

55
[![Java 8 CI](https://github.com/filip26/copper-multibase/actions/workflows/java8-build.yml/badge.svg)](https://github.com/filip26/copper-multibase/actions/workflows/java8-build.yml)
6+
[![javadoc](https://javadoc.io/badge2/com.apicatalog/copper-multibase/javadoc.svg)](https://javadoc.io/doc/com.apicatalog/copper-multibase)
67
[![Maven Central](https://img.shields.io/maven-central/v/com.apicatalog/copper-multibase.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:com.apicatalog%20AND%20a:copper-multibase)
78
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
89

@@ -74,16 +75,10 @@ var decoder = MultibaseDecorer.getInstance(mybase, ...);
7475
<dependency>
7576
<groupId>com.apicatalog</groupId>
7677
<artifactId>copper-multibase</artifactId>
77-
<version>4.0.0</version>
78+
<version>4.1.0</version>
7879
</dependency>
7980
```
8081

81-
## Documentation
82-
83-
[![javadoc](https://javadoc.io/badge2/com.apicatalog/copper-multibase/javadoc.svg)](https://javadoc.io/doc/com.apicatalog/copper-multibase)
84-
85-
86-
8782
## Contributing
8883

8984
All PR's welcome!

SECURITY.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
| ------- |:---------:|
7+
| 4.x.x | ✅ Supported |
8+
| 1.x.x | ❌ Not supported |
9+
| 0.x.x | ❌ Not supported |
10+
11+
## Reporting a Vulnerability
12+
13+
If you discover a security vulnerability, please report it responsibly by contacting:
14+
15+
**Filip Kolarik**
16+
📧 [filip26@gmail.com](mailto:filip26@gmail.com)
17+
18+
We will investigate promptly and work with you to address the issue. Thank you for helping keep the project secure!

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>com.apicatalog</groupId>
99
<artifactId>copper-multibase</artifactId>
10-
<version>4.0.0</version>
10+
<version>4.1.0</version>
1111
<packaging>jar</packaging>
1212

1313
<name>Copper Multibase</name>

src/main/java/com/apicatalog/multibase/MultibaseDecoder.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ public Optional<Multibase> getBase(final String encoded) {
8585
return getBase(encoded.charAt(0));
8686
}
8787

88+
/**
89+
* Finds a registered {@link Multibase} encoding by its name.
90+
*
91+
* <p>
92+
* This method searches through all multibases registered with this decoder and
93+
* returns the first whose {@link Multibase#name()} matches the given name
94+
* exactly.
95+
* </p>
96+
*
97+
* @param name the name of the multibase encoding (must not be {@code null})
98+
* @return an {@code Optional} containing the matching {@link Multibase}, or an
99+
* empty {@code Optional} if no encoding with the given name is found
100+
* @throws NullPointerException if {@code name} is {@code null}
101+
*/
102+
public final Optional<Multibase> findBase(final String name) {
103+
return bases.values().stream()
104+
.filter(base -> base.name().equals(name))
105+
.findFirst();
106+
}
107+
88108
/**
89109
* Decodes a multibase-encoded string into a byte array.
90110
*
@@ -98,4 +118,32 @@ public byte[] decode(final String encoded) {
98118
.map(base -> base.decode(encoded))
99119
.orElseThrow(() -> new IllegalArgumentException("Unsupported multibase encoding [" + encoded.charAt(0) + "]."));
100120
}
121+
122+
/**
123+
* Returns an unmodifiable view of the registered multibase encodings.
124+
*
125+
* <p>
126+
* The returned map associates each multibase prefix character with its
127+
* corresponding {@link Multibase} instance. Attempts to modify the map (e.g.
128+
* {@code put}, {@code remove}) will result in an
129+
* {@link UnsupportedOperationException}.
130+
* </p>
131+
*
132+
* @return an unmodifiable map of prefix characters to {@link Multibase}
133+
* instances
134+
*/
135+
public Map<Character, Multibase> bases() {
136+
return bases;
137+
}
138+
139+
/**
140+
* Returns the number of multibase encodings currently registered with this
141+
* decoder.
142+
*
143+
* @return the count of registered encodings
144+
*/
145+
public long size() {
146+
return bases.size();
147+
}
148+
101149
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Support for <a href="https://multiformats.io/multibase/">multibase</a>.
3+
*
4+
* <p>
5+
* Multibase is a <em>self-describing format</em> for encoding binary data as
6+
* text. A multibase-encoded string is prefixed with a single character that
7+
* uniquely identifies the base encoding (e.g., {@code 'z'} for Base58-BTC,
8+
* {@code 'm'} for Base64). This allows encoded data to carry along the
9+
* information needed for correct decoding.
10+
* </p>
11+
*
12+
* <p>
13+
* This package provides:
14+
* </p>
15+
* <ul>
16+
* <li>{@link com.apicatalog.multibase.Multibase} – definition of an encoding
17+
* format including its name, prefix, alphabet length, and encode/decode
18+
* functions.</li>
19+
* <li>{@link com.apicatalog.multibase.MultibaseDecoder} – utility for resolving
20+
* a registered encoding from its prefix or name and decoding multibase-encoded
21+
* strings.</li>
22+
* </ul>
23+
*
24+
* <p>
25+
* A set of built-in multibase encodings is available via
26+
* {@link com.apicatalog.multibase.Multibase#provided()}.
27+
* </p>
28+
*/
29+
package com.apicatalog.multibase;

0 commit comments

Comments
 (0)