static ASN1ObjectIdentifier fromOctetString(byte[] enc)
    {
        if (enc.length < 3)
        {
            return new ASN1ObjectIdentifier(enc);
        }

        int idx1 = enc[enc.length - 2] & 0xff;
        ASN1ObjectIdentifier[] first = cache[idx1];

        if (first == null)
        {
            first = cache[idx1] = new ASN1ObjectIdentifier[255];
        }

        int idx2 = enc[enc.length - 1] & 0xff;

        ASN1ObjectIdentifier possibleMatch = first[idx2];

        if (possibleMatch == null)
        {
            possibleMatch = first[idx2] = new ASN1ObjectIdentifier(enc);
            return possibleMatch;
        }

        if (Arrays.areEqual(enc, possibleMatch.getBody()))
        {
            return possibleMatch;
        }
        else
        {
            idx1 = (idx1 + 1) % 256;
            first = cache[idx1];
            if (first == null)
            {
                first = cache[idx1] = new ASN1ObjectIdentifier[255];
            }

            possibleMatch = first[idx2];

            if (possibleMatch == null)
            {
                possibleMatch = first[idx2] = new ASN1ObjectIdentifier(enc);
                return possibleMatch;
            }

            if (Arrays.areEqual(enc, possibleMatch.getBody()))
            {
                return possibleMatch;
            }

            idx2 = (idx2 + 1) % 256;
            possibleMatch = first[idx2];

            if (possibleMatch == null)
            {
                possibleMatch = first[idx2] = new ASN1ObjectIdentifier(enc);
                return possibleMatch;
            }

            if (Arrays.areEqual(enc, possibleMatch.getBody()))
            {
                return possibleMatch;
            }
        }

        return new ASN1ObjectIdentifier(enc);
    }