Example usage for org.eclipse.jgit.util NB encodeInt64

List of usage examples for org.eclipse.jgit.util NB encodeInt64

Introduction

In this page you can find the example usage for org.eclipse.jgit.util NB encodeInt64.

Prototype

public static void encodeInt64(final byte[] intbuf, final int offset, long v) 

Source Link

Document

Write a 64 bit integer as a sequence of 8 bytes (network byte order).

Usage

From source file:com.google.gerrit.gpg.PublicKeyStore.java

License:Apache License

static ObjectId keyObjectId(long keyId) {
    byte[] buf = new byte[Constants.OBJECT_ID_LENGTH];
    NB.encodeInt64(buf, 0, keyId);
    return ObjectId.fromRaw(buf);
}

From source file:com.google.gerrit.httpd.raw.CatServlet.java

License:Apache License

private String rand(final HttpServletRequest req, final String suffix) throws UnsupportedEncodingException {
    // Produce a random suffix that is difficult (or nearly impossible)
    // for an attacker to guess in advance. This reduces the risk that
    // an attacker could upload a *.class file and have us send a ZIP
    // that can be invoked through an applet tag in the victim's browser.
    ////from   ww  w .  j  ava 2  s .  c om
    final MessageDigest md = Constants.newMessageDigest();
    final byte[] buf = new byte[8];

    NB.encodeInt32(buf, 0, req.getRemotePort());
    md.update(req.getRemoteAddr().getBytes("UTF-8"));
    md.update(buf, 0, 4);

    NB.encodeInt64(buf, 0, TimeUtil.nowMs());
    md.update(buf, 0, 8);

    rng.nextBytes(buf);
    md.update(buf, 0, 8);

    return suffix + "-" + ObjectId.fromRaw(md.digest()).name();
}

From source file:com.google.gerrit.server.change.FileContentUtil.java

License:Apache License

private static String randSuffix() {
    // Produce a random suffix that is difficult (or nearly impossible)
    // for an attacker to guess in advance. This reduces the risk that
    // an attacker could upload a *.class file and have us send a ZIP
    // that can be invoked through an applet tag in the victim's browser.
    ////from   ww  w. j  a  v a  2 s . c  o m
    Hasher h = Hashing.md5().newHasher();
    byte[] buf = new byte[8];

    NB.encodeInt64(buf, 0, TimeUtil.nowMs());
    h.putBytes(buf);

    rng.nextBytes(buf);
    h.putBytes(buf);

    return h.hash().toString();
}