FileDocCategorySizeDatePackage
Signature.javaAPI DocAndroid 1.5 API4694Wed May 06 22:41:54 BST 2009android.content.pm

Signature

public class Signature extends Object implements android.os.Parcelable
Opaque, immutable representation of a signature associated with an application package.

Fields Summary
private final byte[]
mSignature
private int
mHashCode
private boolean
mHaveHashCode
private String
mString
public static final Parcelable.Creator
CREATOR
Constructors Summary
public Signature(byte[] signature)
Create Signature from an existing raw byte array.

        mSignature = signature.clone();
    
private Signature(android.os.Parcel source)


       
        mSignature = source.createByteArray();
    
public Signature(String text)
Create Signature from a text representation previously returned by {@link #toChars} or {@link #toCharsString()}.

        final int N = text.length()/2;
        byte[] sig = new byte[N];
        for (int i=0; i<N; i++) {
            char c = text.charAt(i*2);
            byte b = (byte)(
                    (c >= 'a" ? (c - 'a" + 10) : (c - '0"))<<4);
            c = text.charAt(i*2 + 1);
            b |= (byte)(c >= 'a" ? (c - 'a" + 10) : (c - '0"));
            sig[i] = b;
        }
        mSignature = sig;
    
Methods Summary
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object obj)

        try {
            if (obj != null) {
                Signature other = (Signature)obj;
                return Arrays.equals(mSignature, other.mSignature);
            }
        } catch (ClassCastException e) {
        }
        return false;
    
public inthashCode()

        if (mHaveHashCode) {
            return mHashCode;
        }
        mHashCode = Arrays.hashCode(mSignature);
        mHaveHashCode = true;
        return mHashCode;
    
public byte[]toByteArray()

return
the contents of this signature as a byte array.

        byte[] bytes = new byte[mSignature.length];
        System.arraycopy(mSignature, 0, bytes, 0, mSignature.length);
        return bytes;
    
public char[]toChars()
Encode the Signature as ASCII text.

        return toChars(null, null);
    
public char[]toChars(char[] existingArray, int[] outLen)
Encode the Signature as ASCII text in to an existing array.

param
existingArray Existing char array or null.
param
outLen Output parameter for the number of characters written in to the array.
return
Returns either existingArray if it was large enough to hold the ASCII representation, or a newly created char[] array if needed.

        byte[] sig = mSignature;
        final int N = sig.length;
        final int N2 = N*2;
        char[] text = existingArray == null || N2 > existingArray.length
                ? new char[N2] : existingArray;
        for (int j=0; j<N; j++) {
            byte v = sig[j];
            int d = (v>>4)&0xf;
            text[j*2] = (char)(d >= 10 ? ('a" + d - 10) : ('0" + d));
            d = v&0xf;
            text[j*2+1] = (char)(d >= 10 ? ('a" + d - 10) : ('0" + d));
        }
        if (outLen != null) outLen[0] = N;
        return text;
    
public java.lang.StringtoCharsString()
Return the result of {@link #toChars()} as a String. This result is cached so future calls will return the same String.

        if (mString != null) return mString;
        String str = new String(toChars());
        mString = str;
        return mString;
    
public voidwriteToParcel(android.os.Parcel dest, int parcelableFlags)

        dest.writeByteArray(mSignature);