mirror of
https://codeberg.org/PGPainless/vks-java.git
synced 2024-11-22 07:22:06 +01:00
Add missing javadoc
This commit is contained in:
parent
a36e01d7d2
commit
0dc7ba1ecb
11 changed files with 176 additions and 4 deletions
|
@ -9,20 +9,54 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request email verification for email addresses of user-ids on a certificate.
|
||||||
|
*/
|
||||||
public interface RequestVerify {
|
public interface RequestVerify {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request email verification for the given email address.
|
||||||
|
*
|
||||||
|
* @param emailAddress email address
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
default ForEmailAddresses forEmailAddress(String emailAddress) {
|
default ForEmailAddresses forEmailAddress(String emailAddress) {
|
||||||
return forEmailAddresses(emailAddress);
|
return forEmailAddresses(emailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request email verification for one or more email addresses.
|
||||||
|
*
|
||||||
|
* @param emailAddresses email addresses
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
ForEmailAddresses forEmailAddresses(String... emailAddresses);
|
ForEmailAddresses forEmailAddresses(String... emailAddresses);
|
||||||
|
|
||||||
interface ForEmailAddresses {
|
interface ForEmailAddresses {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the verification request using the given <pre>token</pre>, retrieved earlier by uploading the
|
||||||
|
* certificate to the server.
|
||||||
|
*
|
||||||
|
* @param token access token to authorize the request
|
||||||
|
* @return servers successful response
|
||||||
|
*
|
||||||
|
* @throws IOException in case of an error
|
||||||
|
*/
|
||||||
default Response execute(String token) throws IOException {
|
default Response execute(String token) throws IOException {
|
||||||
return execute(token, Arrays.asList("en_US", "en_GB"));
|
return execute(token, Arrays.asList("en_US", "en_GB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the verification request using the given <pre>token</pre>, retrieved earlier by uploading the
|
||||||
|
* certificate to the server.
|
||||||
|
*
|
||||||
|
* @param token access token to authorize the request
|
||||||
|
* @param locale list of preferred locales for the verification emails
|
||||||
|
* @return servers successful response
|
||||||
|
*
|
||||||
|
* @throws IOException in case of an error
|
||||||
|
*/
|
||||||
Response execute(String token, List<String> locale) throws IOException;
|
Response execute(String token, List<String> locale) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,14 +75,29 @@ public interface RequestVerify {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the uppercase OpenPGP fingerprint of the certificate.
|
||||||
|
*
|
||||||
|
* @return fingerprint
|
||||||
|
*/
|
||||||
public String getKeyFingerprint() {
|
public String getKeyFingerprint() {
|
||||||
return keyFingerprint;
|
return keyFingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a map of {@link Status States} of email addresses of user-ids on the certificate after requesting
|
||||||
|
* verification.
|
||||||
|
* @return status map
|
||||||
|
*/
|
||||||
public Map<String, Status> getStatus() {
|
public Map<String, Status> getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an access token to be used to make further requests to the API.
|
||||||
|
*
|
||||||
|
* @return token
|
||||||
|
*/
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
package pgp.vks.client;
|
package pgp.vks.client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing different states an email address of a user-id on a certificate can be in.
|
||||||
|
*/
|
||||||
public enum Status {
|
public enum Status {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,6 +27,11 @@ public class VKSImpl implements VKS {
|
||||||
this.api = new URLMapper(vksService);
|
this.api = new URLMapper(vksService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a {@link VKSImpl} instance targeting the <pre>https://keys.openpgp.org</pre> VKS.
|
||||||
|
*
|
||||||
|
* @return VKS instance
|
||||||
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static VKS keysDotOpenPgpDotOrg() {
|
public static VKS keysDotOpenPgpDotOrg() {
|
||||||
return new VKSImpl("https://keys.openpgp.org");
|
return new VKSImpl("https://keys.openpgp.org");
|
||||||
|
|
|
@ -6,6 +6,9 @@ package pgp.vks.client.exception;
|
||||||
|
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception gets thrown when a public key certificate cannot be published for some reason.
|
||||||
|
*/
|
||||||
public class CertCannotBePublishedException extends ConnectException {
|
public class CertCannotBePublishedException extends ConnectException {
|
||||||
|
|
||||||
public CertCannotBePublishedException(String errorMessage) {
|
public CertCannotBePublishedException(String errorMessage) {
|
||||||
|
|
|
@ -6,12 +6,11 @@ package pgp.vks.client.exception;
|
||||||
|
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception gets thrown when the queried OpenPGP certificate cannot be found on the server.
|
||||||
|
*/
|
||||||
public class CertNotFoundException extends ConnectException {
|
public class CertNotFoundException extends ConnectException {
|
||||||
|
|
||||||
public CertNotFoundException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CertNotFoundException(String message) {
|
public CertNotFoundException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
package pgp.vks.client.exception;
|
package pgp.vks.client.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception gets thrown when an unsupported API {@link pgp.vks.client.VKS.Version} is used.
|
||||||
|
* E.g. user wants to use some command using v2 API, but implementation only supports v1.
|
||||||
|
*/
|
||||||
public class UnsupportedApiException extends RuntimeException {
|
public class UnsupportedApiException extends RuntimeException {
|
||||||
|
|
||||||
public UnsupportedApiException(String message) {
|
public UnsupportedApiException(String message) {
|
||||||
|
|
|
@ -6,6 +6,11 @@ package pgp.vks.client.v1.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error response that gets returned by the server if a POST request fails.
|
||||||
|
*
|
||||||
|
* @see <a href="https://keys.openpgp.org/about/api">VKS API Documentation</a>
|
||||||
|
*/
|
||||||
public class ErrorResponseDto {
|
public class ErrorResponseDto {
|
||||||
|
|
||||||
private final String error;
|
private final String error;
|
||||||
|
@ -14,6 +19,11 @@ public class ErrorResponseDto {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the error message.
|
||||||
|
*
|
||||||
|
* @return error message
|
||||||
|
*/
|
||||||
@JsonProperty("error")
|
@JsonProperty("error")
|
||||||
public String getError() {
|
public String getError() {
|
||||||
return error;
|
return error;
|
||||||
|
|
|
@ -14,6 +14,11 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request for uploading a certificate to the VKS.
|
||||||
|
*
|
||||||
|
* @see <a href="https://keys.openpgp.org/about/api">VKS API Documentation</a>
|
||||||
|
*/
|
||||||
public class UploadRequestDto {
|
public class UploadRequestDto {
|
||||||
|
|
||||||
private static final byte[] ARMOR_HEADER = "-----BEGIN PGP PUBLIC KEY BLOCK-----".getBytes(Charset.forName("UTF8"));
|
private static final byte[] ARMOR_HEADER = "-----BEGIN PGP PUBLIC KEY BLOCK-----".getBytes(Charset.forName("UTF8"));
|
||||||
|
@ -24,6 +29,15 @@ public class UploadRequestDto {
|
||||||
this.keytext = keytext;
|
this.keytext = keytext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@link UploadRequestDto} from an ASCII armored or binary OpenPGP certificate which is read from the
|
||||||
|
* given <pre>certInStream</pre>.
|
||||||
|
*
|
||||||
|
* @param certInStream {@link InputStream} containing the ASCII armored or binary OpenPGP certificate
|
||||||
|
* @return request DTO
|
||||||
|
*
|
||||||
|
* @throws IOException in case of an IO error
|
||||||
|
*/
|
||||||
public static UploadRequestDto fromInputStream(InputStream certInStream) throws IOException {
|
public static UploadRequestDto fromInputStream(InputStream certInStream) throws IOException {
|
||||||
ByteArrayOutputStream certBuf = new ByteArrayOutputStream();
|
ByteArrayOutputStream certBuf = new ByteArrayOutputStream();
|
||||||
Streams.pipeAll(certInStream, certBuf);
|
Streams.pipeAll(certInStream, certBuf);
|
||||||
|
@ -31,11 +45,26 @@ public class UploadRequestDto {
|
||||||
return fromBytes(certBuf.toByteArray());
|
return fromBytes(certBuf.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@link UploadRequestDto} from an ASCII armored or binary OpenPGP certificate which is read from the
|
||||||
|
* given <pre>keytext</pre> byte array.
|
||||||
|
*
|
||||||
|
* @param keytext byte array containing the ASCII armored or binary OpenPGP certificate
|
||||||
|
* @return request DTO
|
||||||
|
*/
|
||||||
public static UploadRequestDto fromBytes(byte[] keytext) {
|
public static UploadRequestDto fromBytes(byte[] keytext) {
|
||||||
String armoredOrBase64 = new String(base64IfNecessary(keytext));
|
String armoredOrBase64 = new String(base64IfNecessary(keytext));
|
||||||
return new UploadRequestDto(armoredOrBase64);
|
return new UploadRequestDto(armoredOrBase64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare a serialized OpenPGP certificate for upload.
|
||||||
|
* If the given <pre>certBytes</pre> contain an ASCII armored OpenPGP certificate, do nothing.
|
||||||
|
* Otherwise, consider the bytes to be the binary representation of an OpenPGP certificate and wrap it in Base64 encoding.
|
||||||
|
*
|
||||||
|
* @param certBytes certificate bytes
|
||||||
|
* @return Unmodified ASCII armored, or base64 encoded binary OpenPGP certificate
|
||||||
|
*/
|
||||||
private static byte[] base64IfNecessary(byte[] certBytes) {
|
private static byte[] base64IfNecessary(byte[] certBytes) {
|
||||||
if (!Arrays.areEqual(certBytes, 0, ARMOR_HEADER.length, ARMOR_HEADER, 0, ARMOR_HEADER.length)) {
|
if (!Arrays.areEqual(certBytes, 0, ARMOR_HEADER.length, ARMOR_HEADER, 0, ARMOR_HEADER.length)) {
|
||||||
certBytes = Base64.encode(certBytes);
|
certBytes = Base64.encode(certBytes);
|
||||||
|
|
|
@ -11,6 +11,11 @@ import pgp.vks.client.Upload;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The VKS servers response to a successful upload.
|
||||||
|
*
|
||||||
|
* @see <a href="https://keys.openpgp.org/about/api">VKS API Documentation</a>
|
||||||
|
*/
|
||||||
public class UploadResponseDto {
|
public class UploadResponseDto {
|
||||||
|
|
||||||
private final String key_fpr;
|
private final String key_fpr;
|
||||||
|
@ -25,21 +30,41 @@ public class UploadResponseDto {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uppercase fingerprint of the uploaded OpenPGP certificate.
|
||||||
|
*
|
||||||
|
* @return fingerprint
|
||||||
|
*/
|
||||||
@JsonProperty("key_fpr")
|
@JsonProperty("key_fpr")
|
||||||
public String getKeyFingerprint() {
|
public String getKeyFingerprint() {
|
||||||
return key_fpr;
|
return key_fpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access token which can be used for a limited time to request verification emails for user-ids on the certificate.
|
||||||
|
*
|
||||||
|
* @return access token
|
||||||
|
*/
|
||||||
@JsonProperty("token")
|
@JsonProperty("token")
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of {@link Status States} of email addresses of user-ids on the certificate.
|
||||||
|
*
|
||||||
|
* @return email status map
|
||||||
|
*/
|
||||||
@JsonProperty("status")
|
@JsonProperty("status")
|
||||||
public Map<String, Status> getStatus() {
|
public Map<String, Status> getStatus() {
|
||||||
return new HashMap<>(status);
|
return new HashMap<>(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the DTO into an entity.
|
||||||
|
*
|
||||||
|
* @return entity
|
||||||
|
*/
|
||||||
public Upload.Response toEntity() {
|
public Upload.Response toEntity() {
|
||||||
return new Upload.Response(getKeyFingerprint(), getStatus(), getToken());
|
return new Upload.Response(getKeyFingerprint(), getStatus(), getToken());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request for email verification of one or more unpublished/pending user-ids.
|
||||||
|
*
|
||||||
|
* @see <a href="https://keys.openpgp.org/about/api">VKS API Documentation</a>
|
||||||
|
*/
|
||||||
public class VerificationRequestDto {
|
public class VerificationRequestDto {
|
||||||
|
|
||||||
private final String token;
|
private final String token;
|
||||||
|
@ -22,16 +27,31 @@ public class VerificationRequestDto {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the token which was previously required by uploading a certificate using an {@link UploadRequestDto}.
|
||||||
|
*
|
||||||
|
* @return access token used to authenticate the request
|
||||||
|
*/
|
||||||
@JsonProperty("token")
|
@JsonProperty("token")
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link List} of email addresses for which to request email verification.
|
||||||
|
*
|
||||||
|
* @return email addresses
|
||||||
|
*/
|
||||||
@JsonProperty("addresses")
|
@JsonProperty("addresses")
|
||||||
public List<String> getAddresses() {
|
public List<String> getAddresses() {
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link List} of preferred locales for the verification mails.
|
||||||
|
*
|
||||||
|
* @return locale list
|
||||||
|
*/
|
||||||
@JsonProperty("locale")
|
@JsonProperty("locale")
|
||||||
public List<String> getLocale() {
|
public List<String> getLocale() {
|
||||||
return locale;
|
return locale;
|
||||||
|
|
|
@ -10,6 +10,11 @@ import pgp.vks.client.Status;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VKS servers response to a successful verification request.
|
||||||
|
*
|
||||||
|
* @see <a href="https://keys.openpgp.org/about/api">VKS API Documentation</a>
|
||||||
|
*/
|
||||||
public class VerificationResponseDto {
|
public class VerificationResponseDto {
|
||||||
|
|
||||||
private final String key_fpr;
|
private final String key_fpr;
|
||||||
|
@ -24,21 +29,41 @@ public class VerificationResponseDto {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uppercase OpenPGP fingerprint of the certificate.
|
||||||
|
*
|
||||||
|
* @return fingerprint
|
||||||
|
*/
|
||||||
@JsonProperty("key_fpr")
|
@JsonProperty("key_fpr")
|
||||||
public String getKeyFingerprint() {
|
public String getKeyFingerprint() {
|
||||||
return key_fpr;
|
return key_fpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access token which can be used to authenticate further verification requests.
|
||||||
|
*
|
||||||
|
* @return token
|
||||||
|
*/
|
||||||
@JsonProperty("token")
|
@JsonProperty("token")
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of {@link Status States} of email addresses of user-ids on the certificate.
|
||||||
|
*
|
||||||
|
* @return email address status map
|
||||||
|
*/
|
||||||
@JsonProperty("status")
|
@JsonProperty("status")
|
||||||
public Map<String, Status> getStatus() {
|
public Map<String, Status> getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert this DTO to an entity.
|
||||||
|
*
|
||||||
|
* @return entity
|
||||||
|
*/
|
||||||
public RequestVerify.Response toEntity() {
|
public RequestVerify.Response toEntity() {
|
||||||
return new RequestVerify.Response(getKeyFingerprint(), getStatus(), getToken());
|
return new RequestVerify.Response(getKeyFingerprint(), getStatus(), getToken());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue