OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package asn1 | 5 package asn1 |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "io" | 10 "io" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return out.WriteByte(0) | 344 return out.WriteByte(0) |
345 } | 345 } |
346 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.In
t64: | 346 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.In
t64: |
347 return marshalInt64(out, int64(v.Int())) | 347 return marshalInt64(out, int64(v.Int())) |
348 case reflect.Struct: | 348 case reflect.Struct: |
349 t := v.Type() | 349 t := v.Type() |
350 | 350 |
351 startingField := 0 | 351 startingField := 0 |
352 | 352 |
353 // If the first element of the structure is a non-empty | 353 // If the first element of the structure is a non-empty |
354 » » // RawContents, then we don't bother serialising the rest. | 354 » » // RawContents, then we don't bother serializing the rest. |
355 if t.NumField() > 0 && t.Field(0).Type == rawContentsType { | 355 if t.NumField() > 0 && t.Field(0).Type == rawContentsType { |
356 s := v.Field(0) | 356 s := v.Field(0) |
357 if s.Len() > 0 { | 357 if s.Len() > 0 { |
358 bytes := make([]byte, s.Len()) | 358 bytes := make([]byte, s.Len()) |
359 for i := 0; i < s.Len(); i++ { | 359 for i := 0; i < s.Len(); i++ { |
360 bytes[i] = uint8(s.Index(i).Uint()) | 360 bytes[i] = uint8(s.Index(i).Uint()) |
361 } | 361 } |
362 /* The RawContents will contain the tag and | 362 /* The RawContents will contain the tag and |
363 * length fields but we'll also be writing | 363 * length fields but we'll also be writing |
364 » » » » * those outselves, so we strip them out of | 364 » » » » * those ourselves, so we strip them out of |
365 * bytes */ | 365 * bytes */ |
366 _, err = out.Write(stripTagAndLength(bytes)) | 366 _, err = out.Write(stripTagAndLength(bytes)) |
367 return | 367 return |
368 } else { | 368 } else { |
369 startingField = 1 | 369 startingField = 1 |
370 } | 370 } |
371 } | 371 } |
372 | 372 |
373 for i := startingField; i < t.NumField(); i++ { | 373 for i := startingField; i < t.NumField(); i++ { |
374 var pre *forkableWriter | 374 var pre *forkableWriter |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 var out bytes.Buffer | 495 var out bytes.Buffer |
496 v := reflect.ValueOf(val) | 496 v := reflect.ValueOf(val) |
497 f := newForkableWriter() | 497 f := newForkableWriter() |
498 err := marshalField(f, v, fieldParameters{}) | 498 err := marshalField(f, v, fieldParameters{}) |
499 if err != nil { | 499 if err != nil { |
500 return nil, err | 500 return nil, err |
501 } | 501 } |
502 _, err = f.writeTo(&out) | 502 _, err = f.writeTo(&out) |
503 return out.Bytes(), nil | 503 return out.Bytes(), nil |
504 } | 504 } |
OLD | NEW |