EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.chrome.browser.util]

COVERAGE SUMMARY FOR SOURCE FILE [HashUtil.java]

nameclass, %method, %block, %line, %
HashUtil.java100% (2/2)88%  (7/8)84%  (91/108)76%  (16/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HashUtil100% (1/1)75%  (3/4)81%  (74/91)67%  (10/15)
HashUtil (): void 0%   (0/1)0%   (0/3)0%   (0/2)
getHash (HashUtil$Params, String): String 100% (1/1)66%  (27/41)57%  (4/7)
encodeHex (byte []): String 100% (1/1)100% (43/43)100% (5/5)
getMd5Hash (HashUtil$Params): String 100% (1/1)100% (4/4)100% (1/1)
     
class HashUtil$Params100% (1/1)100% (4/4)100% (17/17)100% (6/6)
HashUtil$Params (String): void 100% (1/1)100% (6/6)100% (3/3)
access$000 (HashUtil$Params): String 100% (1/1)100% (3/3)100% (1/1)
access$100 (HashUtil$Params): String 100% (1/1)100% (3/3)100% (1/1)
withSalt (String): HashUtil$Params 100% (1/1)100% (5/5)100% (2/2)

1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.chrome.browser.util;
6 
7import android.util.Log;
8 
9import java.security.MessageDigest;
10import java.security.NoSuchAlgorithmException;
11import java.util.Formatter;
12 
13import javax.annotation.Nullable;
14 
15/**
16 * Helper functions for working with hashes.
17 */
18public final class HashUtil {
19    private static final String TAG = "HashUtil";
20 
21    private HashUtil() {
22    }
23 
24    public static class Params {
25        private final String mText;
26        private String mSalt;
27 
28        public Params(String text) {
29            mText = text;
30        }
31 
32        public Params withSalt(String salt) {
33            mSalt = salt;
34            return this;
35        }
36    }
37 
38    public static String getMd5Hash(Params params) {
39        return getHash(params, "MD5");
40    }
41 
42    private static String getHash(Params params, String algorithm) {
43        try {
44            String digestText = params.mText + (params.mSalt == null ? "" : params.mSalt);
45            MessageDigest m = MessageDigest.getInstance(algorithm);
46            byte[] digest = m.digest(digestText.getBytes());
47            return encodeHex(digest);
48        } catch (NoSuchAlgorithmException e) {
49            Log.e(TAG, "Unable to find digest algorithm " + algorithm);
50            return null;
51        }
52    }
53 
54    private static String encodeHex(byte[] data) {
55        StringBuilder sb = new StringBuilder(data.length * 2);
56        Formatter formatter = new Formatter(sb);
57        for (byte b : data) {
58            formatter.format("%02x", b);
59        }
60        return sb.toString();
61    }
62}

[all classes][org.chromium.chrome.browser.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov