public static Sha1Hash forValue (Value<?> value) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            // If the SHA1 algorithm doesn't exist, returns null
            return null;
        }

        BencodeOutputStream bout = new BencodeOutputStream(new DigestOutputStream(new VoidOutputStream(), md));

        try {
            bout.writeValue(value);
        } catch (IOException e) {
            // This should never happen
            // In case it does, this method returns null
            return null;
        } finally {
            bout.close();
        }

        return new Sha1Hash(md.digest());
    }