Internal function used in creating a Sign1Message object from a byte string.

@param obj COSE_Sign1 encoded object.
@throws CoseException Errors generated by the COSE module
14462
protected void DecodeFromCBORObject(CBORObject obj) throws CoseException {
        if (obj.getType() != CBORType.Array) throw new CoseException("Invalid Signer structure");
        
        if (obj.size() != 3) throw new CoseException("Invalid Signer structure");
        
        if (obj.get(0).getType() == CBORType.ByteString) {
            rgbProtected = obj.get(0).GetByteString();
            if (rgbProtected.length == 0) {
                objProtected = CBORObject.NewMap();
            }
            else {
                objProtected = CBORObject.DecodeFromBytes(rgbProtected);
                if (objProtected.size() == 0) rgbProtected = new byte[0];
            }
        }
        else throw new CoseException("Invalid Signer structure");
        
        if (obj.get(1).getType() == CBORType.Map) {
            objUnprotected = obj.get(1);
        }
        else throw new CoseException("Invalid Signer structure");
        
        if (obj.get(2).getType() == CBORType.ByteString) rgbSignature = obj.get(2).GetByteString();
        else if (!obj.get(2).isNull()) throw new CoseException("Invalid Signer structure");

        CBORObject countersignature = this.findAttribute(HeaderKeys.CounterSignature, UNPROTECTED);
        if (countersignature != null) {
            if ((countersignature.getType() != CBORType.Array) ||
                    (countersignature.getValues().isEmpty())) {
                throw new CoseException("Invalid countersignature attribute");
            }
            
            if (countersignature.get(0).getType() == CBORType.Array) {
                for (CBORObject csObj : countersignature.getValues()) {
                    if (csObj.getType() != CBORType.Array) {
                        throw new CoseException("Invalid countersignature attribute");
                    }
                    
                    CounterSign cs = new CounterSign(csObj);
                    cs.setObject(this);
                    this.addCountersignature(cs);
                }
            }
            else {
                CounterSign cs = new CounterSign(countersignature);
                cs.setObject(this);
                this.addCountersignature(cs);
            }
        }
        
        countersignature = this.findAttribute(HeaderKeys.CounterSignature0, UNPROTECTED);
        if (countersignature != null) {
            if (countersignature.getType() != CBORType.ByteString) {
                throw new CoseException("Invalid Countersignature0 attribute");
            }
            
            CounterSign1 cs = new CounterSign1(countersignature.GetByteString());
            cs.setObject(this);
            this.counterSign1 = cs;
        }
    }
905650
function Sign(key) {
    var self = this;

    /** default encoding to use in all string operations */
    self.defaultEncoding = undefined;

    if( key instanceof SignKey) {
        self.iKey = key;
    }
    else {
        /** Set of keys used to encrypt and decrypt messages */
        self.iKey = new SignKey();
    }

    /** Size of the generated message signature */
    self.bytes = function() {
        return binding.crypto_sign_BYTES;
    };

    /** String name of the default crypto primitive used in sign operations */
    self.primitive = function() {
        return binding.crypto_sign_PRIMITIVE;
    };

    /**
     * Get the keypair object
     * @returns {SignKey|*}
     */
    self.key = function() {
        return self.iKey;
    };

    /**
     * @return {Number} The size of the message signature
     */
    self.size = function() {
        return binding.crypto_sign_BYTES;
    };

    /**
     * Set the default encoding to use in all string conversions
     * @param {String} encoding  encoding to use
     */
    self.setEncoding = function(encoding) {
        assert(!!encoding.match(/^(?:utf8|ascii|binary|hex|utf16le|ucs2|base64)$/), 'Encoding ' + encoding + ' is currently unsupported.');
        self.defaultEncoding = encoding;
    };

    /**
     * Get the current default encoding
     * @returns {undefined|String}
     */
    self.getEncoding = function() {
        return self.defaultEncoding;
    };

    /**
     * Digitally sign message
     *
     * @param {Buffer|String|Array} message  message to sign
     * @param {String} [encoding]             encoding of message string
     *
     * @returns {Object}                       cipher box
     */
    self.sign = function (message, encoding) {
        encoding = String(encoding) || self.defaultEncoding || 'utf8';

        var buf = toBuffer(message, encoding);

        var signature = binding.crypto_sign(buf, self.iKey.sk().get());
        if( !signature ) {
            return undefined;
        }

        return {
            sign: signature,
            publicKey: self.iKey.pk().get()
        };
    };

    /**
     * Digitally sign message, using detached signature
     *
     * @param {Buffer|String|Array} message  message to sign
     * @param {String} [encoding]            encoding of message string
     *
     * @returns {Object} cipher box
     */
    self.signDetached = function (message, encoding) {
        encoding = String(encoding) || self.defaultEncoding || 'utf8';

        var buf = toBuffer(message, encoding);

        var signature = binding.crypto_sign_detached(buf, self.iKey.sk().get());
        if( !signature ) {
            return undefined;
        }

        return {
            sign: signature,
            publicKey: self.iKey.pk().get()
        };
    };
}
131149
public static void inc(byte[] nonce, byte value) {
        int i = nonce.length - 1;
        nonce[i] += value;
        if (value > 0 && (nonce[i] < 0 || nonce[i] >= value))
            return;
        if (value < 0 && (nonce[i] < 0 && nonce[i] >= value))
            return;

        for (i = i - 1; i >= 0; i--) {
            nonce[i]++;
            if (nonce[i] != 0) break;
        }
    }
881744
@Override
  public byte[] encode(final NetworkConnectionServiceMessage obj) {
    final Codec codec = connFactoryMap.get(obj.getConnectionFactoryId()).getCodec();
    Boolean isStreamingCodec = isStreamingCodecMap.get(codec);
    if (isStreamingCodec == null) {
      isStreamingCodec = codec instanceof StreamingCodec;
      isStreamingCodecMap.putIfAbsent(codec, isStreamingCodec);
    }

    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      try (final DataOutputStream daos = new DataOutputStream(baos)) {
        daos.writeUTF(obj.getConnectionFactoryId());
        daos.writeUTF(obj.getSrcId().toString());
        daos.writeUTF(obj.getDestId().toString());
        daos.writeInt(obj.getData().size());

        if (isStreamingCodec) {
          for (final Object rec : obj.getData()) {
            ((StreamingCodec) codec).encodeToStream(rec, daos);
          }
        } else {
          final Iterable dataList = obj.getData();
          for (final Object message : dataList) {
            final byte[] bytes = codec.encode(message);
            daos.writeInt(bytes.length);
            daos.write(bytes);
          }
        }
        return baos.toByteArray();
      }
    } catch (final IOException e) {
      throw new RuntimeException("IOException", e);
    }
  }
831942
public void sign() throws CoseException {
        if (rgbProtected == null) {
            if (objProtected.size() == 0) rgbProtected = new byte[0];
            else rgbProtected = objProtected.EncodeToBytes();
        }
        
        for (Signer r : signerList) {
            r.sign(rgbProtected, rgbContent);
        }
        
        ProcessCounterSignatures();
    }
684189
static String _dumpAsString(
                                String indent,
                                DERObject obj)
    {
        if (obj instanceof ASN1Sequence)
        {
            StringBuilder buf = new StringBuilder();
            Enumeration e = ((ASN1Sequence) obj).getObjects();
            String tab = indent + TAB;

            buf.append(indent);
            if (obj instanceof BERConstructedSequence)
            {
                buf.append("BER ConstructedSequence");
            }
            else if (obj instanceof DERConstructedSequence)
            {
                buf.append("DER ConstructedSequence");
            }
            else if (obj instanceof BERSequence)
            {
                buf.append("BER Sequence");
            }
            else if (obj instanceof DERSequence)
            {
                buf.append("DER Sequence");
            }
            else
            {
                buf.append("Sequence");
            }

            buf.append(System.getProperty("line.separator"));

            while (e.hasMoreElements())
            {
                Object o = e.nextElement();

                if (o == null || o.equals(new DERNull()))
                {
                    buf.append(tab);
                    buf.append("NULL");
                    buf.append(System.getProperty("line.separator"));
                }
                else if (o instanceof DERObject)
                {
                    buf.append(_dumpAsString(tab, (DERObject) o));
                }
                else
                {
                    buf.append(_dumpAsString(tab, ((DEREncodable) o).getDERObject()));
                }
            }
            return buf.toString();
        }
        else if (obj instanceof DERTaggedObject)
        {
            StringBuilder buf = new StringBuilder();
            String tab = indent + TAB;

            buf.append(indent);
            if (obj instanceof BERTaggedObject)
            {
                buf.append("BER Tagged [");
            }
            else
            {
                buf.append("Tagged [");
            }

            DERTaggedObject o = (DERTaggedObject) obj;

            buf.append(Integer.toString(o.getTagNo()));
            buf.append("]");

            if (!o.isExplicit())
            {
                buf.append(" IMPLICIT ");
            }

            buf.append(System.getProperty("line.separator"));

            if (o.isEmpty())
            {
                buf.append(tab);
                buf.append("EMPTY");
                buf.append(System.getProperty("line.separator"));
            }
            else
            {
                buf.append(_dumpAsString(tab, o.getObject()));
            }

            return buf.toString();
        }
        else if (obj instanceof DERConstructedSet)
        {
            StringBuilder buf = new StringBuilder();
            Enumeration e = ((ASN1Set) obj).getObjects();
            String tab = indent + TAB;

            buf.append(indent);
            buf.append("ConstructedSet");
            buf.append(System.getProperty("line.separator"));

            while (e.hasMoreElements())
            {
                Object o = e.nextElement();

                if (o == null)
                {
                    buf.append(tab);
                    buf.append("NULL");
                    buf.append(System.getProperty("line.separator"));
                }
                else if (o instanceof DERObject)
                {
                    buf.append(_dumpAsString(tab, (DERObject) o));
                }
                else
                {
                    buf.append(_dumpAsString(tab, ((DEREncodable) o).getDERObject()));
                }
            }
            return buf.toString();
        }
        else if (obj instanceof BERSet)
        {
            StringBuilder buf = new StringBuilder();
            Enumeration e = ((ASN1Set) obj).getObjects();
            String tab = indent + TAB;

            buf.append(indent);
            buf.append("BER Set");
            buf.append(System.getProperty("line.separator"));

            while (e.hasMoreElements())
            {
                Object o = e.nextElement();

                if (o == null)
                {
                    buf.append(tab);
                    buf.append("NULL");
                    buf.append(System.getProperty("line.separator"));
                }
                else if (o instanceof DERObject)
                {
                    buf.append(_dumpAsString(tab, (DERObject) o));
                }
                else
                {
                    buf.append(_dumpAsString(tab, ((DEREncodable) o).getDERObject()));
                }
            }
            return buf.toString();
        }
        else if (obj instanceof DERSet)
        {
            StringBuilder buf = new StringBuilder();
            Enumeration e = ((ASN1Set) obj).getObjects();
            String tab = indent + TAB;

            buf.append(indent);
            buf.append("DER Set");
            buf.append(System.getProperty("line.separator"));

            while (e.hasMoreElements())
            {
                Object o = e.nextElement();

                if (o == null)
                {
                    buf.append(tab);
                    buf.append("NULL");
                    buf.append(System.getProperty("line.separator"));
                }
                else if (o instanceof DERObject)
                {
                    buf.append(_dumpAsString(tab, (DERObject) o));
                }
                else
                {
                    buf.append(_dumpAsString(tab, ((DEREncodable) o).getDERObject()));
                }
            }
            return buf.toString();
        }
        else if (obj instanceof DERObjectIdentifier)
        {
            return indent + "ObjectIdentifier(" + ((DERObjectIdentifier) obj).getId() + ")" + System.getProperty("line.separator");
        }
        else if (obj instanceof DERBoolean)
        {
            return indent + "Boolean(" + ((DERBoolean) obj).isTrue() + ")" + System.getProperty("line.separator");
        }
        else if (obj instanceof DERInteger)
        {
            return indent + "Integer(" + ((DERInteger) obj).getValue() + ")" + System.getProperty("line.separator");
        }
        else if (obj instanceof BERConstructedOctetString)
        {
            return indent + "BER Constructed Octet String" + "[" + ((ASN1OctetString) obj).getOctets().length + "] " + System.getProperty("line.separator");
        }
        else if (obj instanceof DEROctetString)
        {
            return indent + "DER Octet String" + "[" + ((ASN1OctetString) obj).getOctets().length + "] " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERBitString)
        {
            return indent + "DER Bit String" + "[" + ((DERBitString) obj).getBytes().length + ", " + ((DERBitString) obj).getPadBits() + "] "
                   + System.getProperty("line.separator");
        }
        else if (obj instanceof DERIA5String)
        {
            return indent + "IA5String(" + ((DERIA5String) obj).getString() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERUTF8String)
        {
            return indent + "UTF8String(" + ((DERUTF8String) obj).getString() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERPrintableString)
        {
            return indent + "PrintableString(" + ((DERPrintableString) obj).getString() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERVisibleString)
        {
            return indent + "VisibleString(" + ((DERVisibleString) obj).getString() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERBMPString)
        {
            return indent + "BMPString(" + ((DERBMPString) obj).getString() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERT61String)
        {
            return indent + "T61String(" + ((DERT61String) obj).getString() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERUTCTime)
        {
            return indent + "UTCTime(" + ((DERUTCTime) obj).getTime() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERGeneralizedTime)
        {
            return indent + "GeneralizedTime(" + ((DERGeneralizedTime) obj).getTime() + ") " + System.getProperty("line.separator");
        }
        else if (obj instanceof DERUnknownTag)
        {
            //TODO liberty if we keep this find Hex
//            return indent + "Unknown " + Integer.toString(((DERUnknownTag)obj).getTag(), 16) + " " + new String(Hex.encode(((DERUnknownTag)obj).getData())) + System.getProperty("line.separator");
            return indent + "Unknown " + Integer.toString(((DERUnknownTag) obj).getTag(), 16) + " " + new String(((DERUnknownTag) obj).getData())
                   + System.getProperty("line.separator");
        }
        else
        {
            return indent + obj.toString() + System.getProperty("line.separator");
        }
    }
1290321
public static void error(Object obj) {
		if (obj instanceof Throwable) {
			Throwable e = (Throwable) obj;
			error(e, e.getMessage());
		} else {
			error("{}", obj);
		}
	}
625388
def save_codeobject(self, obj):
        
        if PY3:  # pragma: no branch
            args = (
                obj.co_argcount, obj.co_kwonlyargcount, obj.co_nlocals, obj.co_stacksize,
                obj.co_flags, obj.co_code, obj.co_consts, obj.co_names, obj.co_varnames,
                obj.co_filename, obj.co_name, obj.co_firstlineno, obj.co_lnotab, obj.co_freevars,
                obj.co_cellvars
            )
        else:
            args = (
                obj.co_argcount, obj.co_nlocals, obj.co_stacksize, obj.co_flags, obj.co_code,
                obj.co_consts, obj.co_names, obj.co_varnames, obj.co_filename, obj.co_name,
                obj.co_firstlineno, obj.co_lnotab, obj.co_freevars, obj.co_cellvars
            )
        self.save_reduce(types.CodeType, args, obj=obj)
1130748
public static Sign sign(SignAlgorithm algorithm, byte[] privateKey, byte[] publicKey) {
		return new Sign(algorithm, privateKey, publicKey);
	}
27189
@Override
    public Builder signWith(String algorithm, Key key) throws KeyException {

        if (algorithm == null || algorithm.isEmpty() || !algorithm.equals(Constants.SIGNATURE_ALG_RS256)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_ALGORITHM_ERR", new Object[] { algorithm, Constants.SIGNATURE_ALG_RS256 });
            throw new KeyException(err);
        }
        if (key == null || !(key instanceof RSAPrivateKey)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_KEY_ERR", new Object[] { algorithm, key });
            throw new KeyException(err);
        }
        alg = algorithm;
        privateKey = key;
        return this;
    }
1067024
void encodeProperty(ByteArrayOutputStream baos, Object value) throws JMSException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "encodeProperty", new Object[]{baos, value});

    // The value should be a non-null String
    if (value instanceof String) {
      super.encodeProperty(baos, STAR_STRING + (String)value);     // The value has to have '*' preprended
    }

    // If it is not a String, something has gone horribly wrong
    else {
      throw (JMSException)JmsErrorUtils.newThrowable(JMSException.class
                                                    ,"INTERNAL_ERROR_CWSIA0362"
                                                    ,new Object[] {"StringPropertyCoder.encodeProperty#1", longName, value}
                                                    ,null
                                                    ,"StringPropertyCoder.encodeProperty#1"
                                                    ,null
                                                    ,tc);
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "encodeProperty");
  }
938663
def signal_to_exception(signum, frame):
    
    if signum == signal.SIGALRM:
        raise SIGALRMException()
    if signum == signal.SIGHUP:
        raise SIGHUPException()
    if signum == signal.SIGUSR1:
        raise SIGUSR1Exception()
    if signum == signal.SIGUSR2:
        raise SIGUSR2Exception()
    raise SignalException(signum)
334956
public final void mOBJECT_IDENT() throws RecognitionException {
        try {
            int _type = OBJECT_IDENT;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // BELScript.g:277:13: ( ( '_' | LETTER | DIGIT )+ )
            // BELScript.g:278:5: ( '_' | LETTER | DIGIT )+
            {
            // BELScript.g:278:5: ( '_' | LETTER | DIGIT )+
            int cnt7=0;
            loop7:
            do {
                int alt7=2;
                int LA7_0 = input.LA(1);

                if ( ((LA7_0>='0' && LA7_0<='9')||(LA7_0>='A' && LA7_0<='Z')||LA7_0=='_'||(LA7_0>='a' && LA7_0<='z')) ) {
                    alt7=1;
                }


                switch (alt7) {
            	case 1 :
            	    // BELScript.g:
            	    {
            	    if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z') ) {
            	        input.consume();

            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        recover(mse);
            	        throw mse;}


            	    }
            	    break;

            	default :
            	    if ( cnt7 >= 1 ) break loop7;
                        EarlyExitException eee =
                            new EarlyExitException(7, input);
                        throw eee;
                }
                cnt7++;
            } while (true);


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
57965
public static Signer updateDEREncodedObject(Signer signer, ASN1Encodable tbsObj)
        throws IOException
    {
        OutputStream sOut = signer.getOutputStream();
        DEROutputStream dOut = new DEROutputStream(sOut);

        dOut.writeObject(tbsObj);

        sOut.close();

        return signer;
    }
43513
@Override
    protected CBORObject EncodeCBORObject() throws CoseException {
        sign();
        
        CBORObject obj = CBORObject.NewArray();
        
        obj.Add(rgbProtected);
        obj.Add(objUnprotected);
        if (emitContent) obj.Add(rgbContent);
        else obj.Add(null);
        CBORObject signers = CBORObject.NewArray();
        obj.Add(signers);
        
        for (Signer r : signerList) {
            signers.Add(r.EncodeToCBORObject());
        }
        
        return obj;
    }
976202
public static final String coerceToString(final ELContext ctx, final Object obj) {
        if (ctx != null) {
        	boolean originalIsPropertyResolved = ctx.isPropertyResolved();
        	try {
        		Object result = ctx.getELResolver().convertToType(ctx, obj, String.class);
        		if (ctx.isPropertyResolved()) {
        			return (String) result;
        		}
        	} finally {
        		ctx.setPropertyResolved(originalIsPropertyResolved);
        	}
        }

        if (obj == null) {
            return "";
        } else if (obj instanceof String) {
            return (String) obj;
        } else if (obj instanceof Enum<?>) {
            return ((Enum<?>) obj).name();
        } else {
            return obj.toString();
        }
    }
725235
@Override
	public void writeObject(Object value) throws JMSException
    {
        if (value != null)
        {
        	// Check supported types
	        if (!(value instanceof Boolean ||
	              value instanceof Byte ||
	              value instanceof Character ||
	              value instanceof Short ||
	              value instanceof Integer ||
	              value instanceof Long ||
	              value instanceof Float ||
	              value instanceof Double ||
	              value instanceof String ||
	              value instanceof byte[]))
	            throw new MessageFormatException("Unsupported value type : "+value.getClass().getName());
        }
        
        write(value);
    }