com.docuverse.identicon

## Class IdenticonUtil

- java.lang.Object
- - com.docuverse.identicon.IdenticonUtil

-     public class IdenticonUtil
      extends Object

  Utility methods useful for implementing identicon functionality. Methods are class methods for convenience.

  Key method of interest is `getIdenticonCode(java.net.InetAddress)` which converts IP address into identicon code.
  IMPORTANT: `inetSalt` value must be set to reasonably long random string prior to invoking this method.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `IdenticonUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `getIdenticonCode(InetAddress inetAddr)` Returns identicon code for given IP address.
    `static int` | `getIdenticonCode(String codeParam, String remoteAddr)` Returns identicon code specified as an input parameter or derived from an IP address.
    `static String` | `getIdenticonETag(int code, int size, int version)`
    `static int` | `getIdenticonSize(String param)`
    `static int` | `getInetMask()` Returns current IP address mask.
    `static String` | `getInetSalt()` Returns current inetSalt value.
    `static void` | `setInetMask(int inetMask)` Sets current IP address mask.
    `static void` | `setInetSalt(String inetSalt)` Sets current inetSalt value.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### IdenticonUtil

          public IdenticonUtil()

  - ### Method Detail

    - #### getIdenticonCode

          public static int getIdenticonCode(InetAddress inetAddr)
                                      throws Exception

      Returns identicon code for given IP address.

      Current implementation uses first four bytes of SHA1(int(mask(ip))+salt) where mask(ip) uses inetMask to remove unwanted bits from IP address. Also, since salt is a string for convenience sake, int(mask(ip)) is converetd into a string and combined with inetSalt prior to hashing.

      Parameters:
        `inetAddr` - IP address
      Returns:
        identicon code for `inetAddr`
      Throws:
        `Exception`

    - #### getIdenticonCode

          public static int getIdenticonCode(String codeParam,
                                             String remoteAddr)

      Returns identicon code specified as an input parameter or derived from an IP address.

      This method is a convenience method intended to be used by servlets like below:

           int code = IdenticonUtil.getIdenticonCode(request.getParameter("code"), request
                          .getRemoteAddr());

      Parameters:
        `codeParam` - code parameter, if `null` remoteAddr parameter will be used to determine the value.
        `remoteAddr` - HTTP requester's IP address. Optional if code was specified.
      Returns:
        the code

    - #### getIdenticonETag

          public static String getIdenticonETag(int code,
                                                int size,
                                                int version)

    - #### getIdenticonSize

          public static int getIdenticonSize(String param)

    - #### getInetMask

          public static int getInetMask()

      Returns current IP address mask. Default is 0xffffffff.
      Returns:
        current IP address mask

    - #### getInetSalt

          public static String getInetSalt()

      Returns current inetSalt value.
      Returns:
        the value

    - #### setInetMask

          public static void setInetMask(int inetMask)

      Sets current IP address mask. Default is 0xffffffff.
      Parameters:
        `inetMask` -

    - #### setInetSalt

          public static void setInetSalt(String inetSalt)

      Sets current inetSalt value.
      Parameters:
        `inetSalt` -