SecretkeyElement.java

  1. /**
  2.  *
  3.  * Copyright 2018 Paul Schaub.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.ox.element;

  18. import java.nio.charset.Charset;

  19. import org.jivesoftware.smack.packet.ExtensionElement;
  20. import org.jivesoftware.smack.util.Objects;
  21. import org.jivesoftware.smack.util.XmlStringBuilder;

  22. /**
  23.  * This class represents a secretkey element which contains a users OpenPGP secret key.
  24.  *
  25.  * @see <a href="https://xmpp.org/extensions/xep-0373.html#client-receives-secret-response">
  26.  *     XEP-0373: ยง5.2.2 PEP Service Success Response</a>
  27.  */
  28. public class SecretkeyElement implements ExtensionElement {

  29.     public static final String NAMESPACE = OpenPgpElement.NAMESPACE;
  30.     public static final String ELEMENT = "secretkey";

  31.     private final byte[] b64Data;

  32.     public SecretkeyElement(byte[] b64Data) {
  33.         this.b64Data = Objects.requireNonNull(b64Data);
  34.     }

  35.     public byte[] getB64Data() {
  36.         return b64Data;
  37.     }

  38.     @Override
  39.     public String getNamespace() {
  40.         return NAMESPACE;
  41.     }

  42.     @Override
  43.     public String getElementName() {
  44.         return ELEMENT;
  45.     }

  46.     @Override
  47.     public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  48.         XmlStringBuilder xml = new XmlStringBuilder(this)
  49.                 .rightAngleBracket()
  50.                 .append(new String(b64Data, Charset.forName("UTF-8")))
  51.                 .closeElement(this);
  52.         return xml;
  53.     }
  54. }