001/*
002 * Copyright 2017-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2017-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.listener;
022
023
024
025import com.unboundid.ldap.sdk.LDAPException;
026import com.unboundid.util.Extensible;
027import com.unboundid.util.ThreadSafety;
028import com.unboundid.util.ThreadSafetyLevel;
029
030
031
032/**
033 * This class defines an API that may be used to format and un-format encoded
034 * passwords for use with the in-memory directory server.
035 */
036@Extensible()
037@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE)
038public abstract class PasswordEncoderOutputFormatter
039{
040  /**
041   * Formats the provided data in accordance with this output format.
042   *
043   * @param  unformattedData  The data to be formatted.  It must not be
044   *                          {@code null}.
045   *
046   * @return  A formatted representation of the provided data.
047   *
048   * @throws  LDAPException  If a problem is encountered while formatting the
049   *                         provided data.
050   */
051  public abstract byte[] format(final byte[] unformattedData)
052         throws LDAPException;
053
054
055
056  /**
057   * Reverses the formatting that has been applied to the provided data.
058   *
059   * @param  formattedData  The formatted data to be un-formatted.  It must not
060   *                        be {@code null}.
061   *
062   * @return  The un-formatted version of the provided data.
063   *
064   * @throws  LDAPException  If the provided data does not represent a valid
065   *                         encoding, or if a problem is encountered while
066   *                         un-formatting the provided data.
067   */
068  public abstract byte[] unFormat(final byte[] formattedData)
069         throws LDAPException;
070
071
072
073  /**
074   * Retrieves a string representation of this password encoder output
075   * formatter.
076   *
077   * @return  A string representation of this password encoder output formatter.
078   */
079  @Override()
080  public final String toString()
081  {
082    final StringBuilder buffer = new StringBuilder();
083    toString(buffer);
084    return buffer.toString();
085  }
086
087
088
089  /**
090   * Appends a string representation of this password encoder output formatter
091   * to the provided buffer.
092   *
093   * @param  buffer  The buffer to which the information should be appended.
094   */
095  public abstract void toString(final StringBuilder buffer);
096}