Esempio n. 1
0
        /**
         * Writes the ptgs to the data buffer, starting at the specified offset.
         *
         * <br/>
         * The 2 byte encode Length field is <b>not</b> written by this method.
         * @return number of bytes written
         */
        public static int SerializePtgs(Ptg[] ptgs, byte[] array, int offset)
        {
            int size = ptgs.Length;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(array, offset);

            ArrayList arrayPtgs = null;

            for (int k = 0; k < size; k++)
            {
                Ptg ptg = ptgs[k];

                ptg.Write(out1);
                if (ptg is ArrayPtg)
                {
                    if (arrayPtgs == null)
                    {
                        arrayPtgs = new ArrayList(5);
                    }
                    arrayPtgs.Add(ptg);
                }
            }
            if (arrayPtgs != null)
            {
                for (int i = 0; i < arrayPtgs.Count; i++)
                {
                    ArrayPtg p = (ArrayPtg)arrayPtgs[i];
                    p.WriteTokenValueBytes(out1);
                }
            }
            return(out1.WriteIndex - offset);;
        }
Esempio n. 2
0
        protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os)
        {
            //XmlOptions xo = new XmlOptions();
            //xo.SetCharacterEncoding("UTF-8");
            Dictionary <String, String> nsMap = new Dictionary <String, String>();

            nsMap.Add(passwordUri.ToString(), "p");
            nsMap.Add(certificateUri.ToString(), "c");
            //xo.UseDefaultNamespace();
            //xo.SaveSuggestedPrefixes(nsMap);
            //xo.SaveNamespacesFirst();
            //xo.SaveAggressiveNamespaces();

            // Setting standalone doesn't work with xmlbeans-2.3 & 2.6
            // ed.DocumentProperties().Standalone=(/*setter*/true);
            //xo.SaveNoXmlDecl();
            MemoryStream bos = new MemoryStream();

            try {
                byte[] buf = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n");
                bos.Write(buf, 0, buf.Length);
                ed.Save(bos);
                os.Write(bos.ToArray());
            } catch (IOException e) {
                throw new EncryptedDocumentException("error marshalling encryption info document", e);
            }
        }
Esempio n. 3
0
 public void Write(LittleEndianByteArrayOutputStream bos)
 {
     bos.WriteShort(info.VersionMajor);
     bos.WriteShort(info.VersionMinor);
     header.Write(bos);
     verifier.Write(bos);
 }
Esempio n. 4
0
        public void TestExtRstEqualsAndHashCode()
        {
            byte[] buf = new byte[200];
            LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
            String str = "\u1d02\u1d12\u1d22";

            bos.WriteShort(1);
            bos.WriteShort(5 * LittleEndianConsts.SHORT_SIZE + str.Length * 2 + 3 * LittleEndianConsts.SHORT_SIZE + 2); // data size
            bos.WriteShort(0x4711);
            bos.WriteShort(0x0815);
            bos.WriteShort(1);
            bos.WriteShort(str.Length);
            bos.WriteShort(str.Length);
            StringUtil.PutUnicodeLE(str, bos);
            bos.WriteShort(1);
            bos.WriteShort(1);
            bos.WriteShort(3);
            bos.WriteShort(42);

            LittleEndianByteArrayInputStream in1 = new LittleEndianByteArrayInputStream(buf, 0, bos.WriteIndex);

            UnicodeString.ExtRst extRst1 = new UnicodeString.ExtRst(in1, bos.WriteIndex);
            in1 = new LittleEndianByteArrayInputStream(buf, 0, bos.WriteIndex);
            UnicodeString.ExtRst extRst2 = new UnicodeString.ExtRst(in1, bos.WriteIndex);

            Assert.AreEqual(extRst1, extRst2);
            Assert.AreEqual(extRst1.GetHashCode(), extRst2.GetHashCode());
        }
Esempio n. 5
0
        public void Write(LittleEndianByteArrayOutputStream bos)
        {
            // see [MS-OFFCRYPTO] - 2.3.4.9
            byte[] salt = Salt;
            Debug.Assert(salt.Length == 16);
            bos.WriteInt(salt.Length); // salt size
            bos.Write(salt);

            // The resulting Verifier value MUST be an array of 16 bytes.
            byte[] encryptedVerifier = EncryptedVerifier;
            Debug.Assert(encryptedVerifier.Length == 16);
            bos.Write(encryptedVerifier);

            // The number of bytes used by the decrypted Verifier hash is given by
            // the VerifierHashSize field, which MUST be 20
            bos.WriteInt(20);

            // EncryptedVerifierHash: An array of bytes that Contains the encrypted form of the hash of
            // the randomly generated Verifier value. The length of the array MUST be the size of the
            // encryption block size multiplied by the number of blocks needed to encrypt the hash of the
            // Verifier. If the encryption algorithm is RC4, the length MUST be 20 bytes. If the encryption
            // algorithm is AES, the length MUST be 32 bytes. After decrypting the EncryptedVerifierHash
            // field, only the first VerifierHashSize bytes MUST be used.
            byte[] encryptedVerifierHash = EncryptedVerifierHash;
            Debug.Assert(encryptedVerifierHash.Length == CipherAlgorithm.encryptedVerifierHashLength);
            bos.Write(encryptedVerifierHash);
        }
Esempio n. 6
0
        public override int Serialize(int offset, byte [] data)
        {
            int recSize  = RecordSize;
            int dataSize = recSize - 4;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, recSize);

            out1.WriteShort(sid);
            out1.WriteShort(dataSize);

            if (_uninterpretedData == null)
            {
                for (int i = 0; i < subrecords.Count; i++)
                {
                    SubRecord record = subrecords[i];
                    record.Serialize(out1);
                }
                int expectedEndIx = offset + dataSize;
                // padding
                while (out1.WriteIndex < expectedEndIx)
                {
                    out1.WriteByte(0);
                }
            }
            else
            {
                out1.Write(_uninterpretedData);
            }
            return(recSize);
        }
Esempio n. 7
0
        /**
         * Serializes the header
         */
        public void Write(LittleEndianByteArrayOutputStream bos)
        {
            int startIdx = bos.WriteIndex;
            ILittleEndianOutput sizeOutput = bos.CreateDelayedOutput(LittleEndianConsts.INT_SIZE);

            bos.WriteInt(Flags);
            bos.WriteInt(0); // size extra
            bos.WriteInt(CipherAlgorithm.ecmaId);
            bos.WriteInt(HashAlgorithm.ecmaId);
            bos.WriteInt(KeySize);
            bos.WriteInt(CipherProvider.ecmaId);
            bos.WriteInt(0); // reserved1
            bos.WriteInt(0); // reserved2
            String cspName = CspName;

            if (cspName == null)
            {
                cspName = CipherProvider.cipherProviderName;
            }
            bos.Write(StringUtil.GetToUnicodeLE(cspName));
            bos.WriteShort(0);
            int headerSize = bos.WriteIndex - startIdx - LittleEndianConsts.INT_SIZE;

            sizeOutput.WriteInt(headerSize);
        }
Esempio n. 8
0
 public void Write(LittleEndianByteArrayOutputStream bos)
 {
     transformInfoHeader.Write(bos);
     bos.WriteInt(extensibilityHeader);
     WriteUtf8LPP4(bos, xrMLLicense);
     bos.WriteInt(4); // where does this 4 come from???
 }
Esempio n. 9
0
File: Ptg.cs Progetto: zzy092/npoi
        /**
         * Writes the ptgs to the data buffer, starting at the specified offset.
         *
         * <br/>
         * The 2 byte encode Length field is <b>not</b> written by this method.
         * @return number of bytes written
         */
        public static int SerializePtgs(Ptg[] ptgs, byte[] array, int offset)
        {
            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(array, offset);

            List <Ptg> arrayPtgs = null;

            foreach (Ptg ptg in ptgs)
            {
                ptg.Write(out1);
                if (ptg is ArrayPtg)
                {
                    if (arrayPtgs == null)
                    {
                        arrayPtgs = new List <Ptg>(5);
                    }
                    arrayPtgs.Add(ptg);
                }
            }
            if (arrayPtgs != null)
            {
                foreach (Ptg arrayPtg in arrayPtgs)
                {
                    ArrayPtg p = (ArrayPtg)arrayPtg;
                    p.WriteTokenValueBytes(out1);
                }
            }
            return(out1.WriteIndex - offset);;
        }
        public override byte[] GetBytes()
        {
            byte[] bytes            = new byte[NPOI.SS.Util.CellRangeAddress.ENCODED_SIZE];
            ILittleEndianOutput leo = new LittleEndianByteArrayOutputStream(bytes, 0);

            this.Record.Serialize(leo);
            return(bytes);
        }
Esempio n. 11
0
        public override int Serialize(int offset, byte[] data)
        {
            LittleEndianOutput      leo  = new LittleEndianByteArrayOutputStream(data, offset);
            ContinuableRecordOutput out1 = new ContinuableRecordOutput(leo, this.Sid);

            Serialize(out1);
            out1.Terminate();
            return(out1.TotalSize);
        }
Esempio n. 12
0
 public void Write(LittleEndianByteArrayOutputStream bos)
 {
     bos.WriteInt(8);
     bos.WriteInt(transformer.Length);
     foreach (String str in transformer)
     {
         WriteUnicodeLPP4(bos, str);
     }
 }
Esempio n. 13
0
 public void Write(LittleEndianByteArrayOutputStream os)
 {
     os.WriteInt(8);
     os.WriteInt(entries.Length);
     foreach (DataSpaceMapEntry dsme in entries)
     {
         dsme.Write(os);
     }
 }
Esempio n. 14
0
 public void Write(LittleEndianByteArrayOutputStream bos)
 {
     WriteUnicodeLPP4(bos, featureIdentifier);
     bos.WriteShort(readerVersionMajor);
     bos.WriteShort(readerVersionMinor);
     bos.WriteShort(updaterVersionMajor);
     bos.WriteShort(updaterVersionMinor);
     bos.WriteShort(writerVersionMajor);
     bos.WriteShort(writerVersionMinor);
 }
Esempio n. 15
0
        //protected internal void SetEncryptedVerifier(byte[] encryptedVerifier)
        //{
        //    base.EncryptedVerifier = (encryptedVerifier);
        //}

        //protected internal void SetEncryptedVerifierHash(byte[] encryptedVerifierHash)
        //{
        //    base.EncryptedVerifierHash = (encryptedVerifierHash);
        //}

        public void Write(LittleEndianByteArrayOutputStream bos)
        {
            byte[] salt = Salt;
            Debug.Assert(salt.Length == 16);
            bos.Write(salt);
            byte[] encryptedVerifier = EncryptedVerifier;
            Debug.Assert(encryptedVerifier.Length == 16);
            bos.Write(encryptedVerifier);
            byte[] encryptedVerifierHash = EncryptedVerifierHash;
            Debug.Assert(encryptedVerifierHash.Length == 16);
            bos.Write(encryptedVerifierHash);
        }
Esempio n. 16
0
        public override int Serialize(int offset, byte[] data)
        {
            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, this.RecordSize);
            int result = this.Serialize(out1);

            if (out1.WriteIndex - offset != this.RecordSize)
            {
                throw new InvalidOperationException("Error in serialization of (" + this.GetType().Name + "): "
                                                    + "Incorrect number of bytes written - expected "
                                                    + this.RecordSize + " but got " + (out1.WriteIndex - offset));
            }
            return(result);
        }
Esempio n. 17
0
            public void Write(LittleEndianByteArrayOutputStream os)
            {
                int start = os.WriteIndex;
                ILittleEndianOutput sizeOut = os.CreateDelayedOutput(LittleEndianConsts.INT_SIZE);

                os.WriteInt(referenceComponent.Length);
                for (int i = 0; i < referenceComponent.Length; i++)
                {
                    os.WriteInt(referenceComponentType[i]);
                    WriteUnicodeLPP4(os, referenceComponent[i]);
                }
                WriteUnicodeLPP4(os, dataSpaceName);
                sizeOut.WriteInt(os.WriteIndex - start);
            }
Esempio n. 18
0
            public void Write(LittleEndianByteArrayOutputStream bos)
            {
                int start = bos.WriteIndex;
                ILittleEndianOutput sizeOut = bos.CreateDelayedOutput(LittleEndianConsts.INT_SIZE);

                bos.WriteInt(transformType);
                WriteUnicodeLPP4(bos, transformerId);
                sizeOut.WriteInt(bos.WriteIndex - start);
                WriteUnicodeLPP4(bos, transformerName);
                bos.WriteShort(readerVersionMajor);
                bos.WriteShort(readerVersionMinor);
                bos.WriteShort(updaterVersionMajor);
                bos.WriteShort(updaterVersionMinor);
                bos.WriteShort(writerVersionMajor);
                bos.WriteShort(writerVersionMinor);
            }
Esempio n. 19
0
        public override int Serialize(int offset, byte[] data)
        {
            int dataSize = DataSize;
            int recSize  = 4 + dataSize;
            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, recSize);

            out1.WriteShort(this.Sid);
            out1.WriteShort(dataSize);
            Serialize(out1);
            if (out1.WriteIndex - offset != recSize)
            {
                throw new InvalidOperationException("Error in serialization of (" + this.GetType().Name + "): "
                                                    + "Incorrect number of bytes written - expected "
                                                    + recSize + " but got " + (out1.WriteIndex - offset));
            }
            return(recSize);
        }
Esempio n. 20
0
        public static DocumentEntry CreateEncryptionEntry(DirectoryEntry dir, String path, EncryptionRecord out1)
        {
            String[] parts = path.Split("/".ToCharArray());
            for (int i = 0; i < parts.Length - 1; i++)
            {
                dir = dir.HasEntry(parts[i])
                    ? (DirectoryEntry)dir.GetEntry(parts[i])
                    : dir.CreateDirectory(parts[i]);
            }

            byte[] buf = new byte[5000];
            LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);

            out1.Write(bos);

            String fileName = parts[parts.Length - 1];

            if (dir.HasEntry(fileName))
            {
                dir.GetEntry(fileName).Delete();
            }

            return(dir.CreateDocument(fileName, bos.WriteIndex, new POIFSWriterListenerImpl(buf)));
        }
Esempio n. 21
0
        /**
         * Writes the ptgs to the data buffer, starting at the specified offset.  
         *
         * <br/>
         * The 2 byte encode Length field is <b>not</b> written by this method.
         * @return number of bytes written
         */
        public static int SerializePtgs(Ptg[] ptgs, byte[] array, int offset)
        {
		    int size = ptgs.Length;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(array, offset);

		    ArrayList arrayPtgs = null;

		    for (int k = 0; k < size; k++) {
			    Ptg ptg = ptgs[k];

			    ptg.Write(out1);
			    if (ptg is ArrayPtg) {
				    if (arrayPtgs == null) {
					    arrayPtgs = new ArrayList(5);
				    }
				    arrayPtgs.Add(ptg);
				    
			    }
		    }
		    if (arrayPtgs != null) {
			    for (int i=0;i<arrayPtgs.Count;i++) {
				    ArrayPtg p = (ArrayPtg)arrayPtgs[i];
				    p.WriteTokenValueBytes(out1);
			    }
		    }
		    return out1.WriteIndex - offset;;
        }
Esempio n. 22
0
 public void Write(LittleEndianByteArrayOutputStream littleendianbytearrayoutputstream)
 {
 }
Esempio n. 23
0
        public override int Serialize(int offset, byte [] data)
        {
            int recSize = RecordSize;
            int dataSize = recSize - 4;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, recSize);

            out1.WriteShort(sid);
            out1.WriteShort(dataSize);

            if (_uninterpretedData == null)
            {
                for (int i = 0; i < subrecords.Count; i++)
                {
                    SubRecord record = subrecords[i];
                    record.Serialize(out1);
                }
                int expectedEndIx = offset + dataSize;
                // padding
                while (out1.WriteIndex < expectedEndIx)
                {
                    out1.WriteByte(0);
                }
            }
            else
            {
                out1.Write(_uninterpretedData);
            }
            return recSize;
        }